diff options
Diffstat (limited to 'src/plugins/renderers/rhi/graphicshelpers')
4 files changed, 1111 insertions, 1001 deletions
diff --git a/src/plugins/renderers/rhi/graphicshelpers/graphicscontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/graphicscontext.cpp index 3358f47f3..4cb0104ac 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/graphicscontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/graphicscontext.cpp @@ -135,11 +135,12 @@ GraphicsContext::GraphicsContext() , m_maxTextureUnits(0) , m_maxImageUnits(0) , m_defaultFBO(0) - , m_gl(nullptr) - , m_glHelper(nullptr) +//* , m_gl(nullptr) +//* , m_glHelper(nullptr) , m_debugLogger(nullptr) , m_currentVAO(nullptr) { + m_contextInfo.m_api = QGraphicsApiFilter::RHI; } GraphicsContext::~GraphicsContext() @@ -148,32 +149,34 @@ GraphicsContext::~GraphicsContext() void GraphicsContext::setOpenGLContext(QOpenGLContext* ctx) { - Q_ASSERT(ctx); - m_gl = ctx; + RHI_UNIMPLEMENTED; +//* Q_ASSERT(ctx); +//* m_gl = ctx; } void GraphicsContext::initialize() { m_initialized = true; - Q_ASSERT(m_gl); +//* Q_ASSERT(m_gl); +//* +//* m_gl->functions()->glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &m_maxTextureUnits); +//* qCDebug(Backend) << "context supports" << m_maxTextureUnits << "texture units"; +//* m_gl->functions()->glGetIntegerv(GL_MAX_IMAGE_UNITS, &m_maxImageUnits); +//* qCDebug(Backend) << "context supports" << m_maxImageUnits << "image units"; +//* +//* if (m_gl->format().majorVersion() >= 3) { +//* m_supportsVAO = true; +//* } else { +//* QSet<QByteArray> extensions = m_gl->extensions(); +//* m_supportsVAO = extensions.contains(QByteArrayLiteral("GL_OES_vertex_array_object")) +//* || extensions.contains(QByteArrayLiteral("GL_ARB_vertex_array_object")) +//* || extensions.contains(QByteArrayLiteral("GL_APPLE_vertex_array_object")); +//* } +//* +//* m_defaultFBO = m_gl->defaultFramebufferObject(); +//* qCDebug(Backend) << "VAO support = " << m_supportsVAO; - m_gl->functions()->glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &m_maxTextureUnits); - qCDebug(Backend) << "context supports" << m_maxTextureUnits << "texture units"; - m_gl->functions()->glGetIntegerv(GL_MAX_IMAGE_UNITS, &m_maxImageUnits); - qCDebug(Backend) << "context supports" << m_maxImageUnits << "image units"; - - if (m_gl->format().majorVersion() >= 3) { - m_supportsVAO = true; - } else { - QSet<QByteArray> extensions = m_gl->extensions(); - m_supportsVAO = extensions.contains(QByteArrayLiteral("GL_OES_vertex_array_object")) - || extensions.contains(QByteArrayLiteral("GL_ARB_vertex_array_object")) - || extensions.contains(QByteArrayLiteral("GL_APPLE_vertex_array_object")); - } - - m_defaultFBO = m_gl->defaultFramebufferObject(); - qCDebug(Backend) << "VAO support = " << m_supportsVAO; } void GraphicsContext::clearBackBuffer(QClearBuffers::BufferTypeFlags buffers) @@ -188,13 +191,16 @@ void GraphicsContext::clearBackBuffer(QClearBuffers::BufferTypeFlags buffers) if (buffers & QClearBuffers::StencilBuffer) mask |= GL_STENCIL_BUFFER_BIT; - m_gl->functions()->glClear(mask); + RHI_UNIMPLEMENTED; +//* m_gl->functions()->glClear(mask); } } bool GraphicsContext::hasValidGLHelper() const { - return m_glHelper != nullptr; + RHI_UNIMPLEMENTED; +//* return m_glHelper != nullptr; + return true; } bool GraphicsContext::isInitialized() const @@ -204,79 +210,85 @@ bool GraphicsContext::isInitialized() const bool GraphicsContext::makeCurrent(QSurface *surface) { - Q_ASSERT(m_gl); - if (!m_gl->makeCurrent(surface)) { - qCWarning(Backend) << Q_FUNC_INFO << "makeCurrent failed"; - return false; - } - - initializeHelpers(surface); + RHI_UNIMPLEMENTED; +//* Q_ASSERT(m_gl); +//* if (!m_gl->makeCurrent(surface)) { +//* qCWarning(Backend) << Q_FUNC_INFO << "makeCurrent failed"; +//* return false; +//* } +//* +//* initializeHelpers(surface); return true; } void GraphicsContext::initializeHelpers(QSurface *surface) { + RHI_UNIMPLEMENTED; // Set the correct GL Helper depending on the surface // If no helper exists, create one - m_glHelper = m_glHelpers.value(surface); - if (!m_glHelper) { - m_glHelper = resolveHighestOpenGLFunctions(); - m_glHelpers.insert(surface, m_glHelper); - } +//* m_glHelper = m_glHelpers.value(surface); +//* if (!m_glHelper) { +//* m_glHelper = resolveHighestOpenGLFunctions(); +//* m_glHelpers.insert(surface, m_glHelper); +//* } } void GraphicsContext::doneCurrent() { - Q_ASSERT(m_gl); - m_gl->doneCurrent(); - m_glHelper = nullptr; + RHI_UNIMPLEMENTED; + //* Q_ASSERT(m_gl); + //* m_gl->doneCurrent(); + //* m_glHelper = nullptr; } // Called by GL Command Thread GraphicsContext::ShaderCreationInfo GraphicsContext::createShaderProgram(RHIShader *shader) { - QOpenGLShaderProgram *shaderProgram = shader->shaderProgram(); - - // Compile shaders - const auto shaderCode = shader->shaderCode(); - - QString logs; - for (int i = QShaderProgram::Vertex; i <= QShaderProgram::Compute; ++i) { - const QShaderProgram::ShaderType type = static_cast<QShaderProgram::ShaderType>(i); - if (!shaderCode.at(i).isEmpty()) { - // Note: logs only return the error but not all the shader code - // we could append it - if (!shaderProgram->addCacheableShaderFromSourceCode(shaderType(type), shaderCode.at(i))) - logs += shaderProgram->log(); - } - } - - // Call glBindFragDataLocation and link the program - // Since we are sharing shaders in the backend, we assume that if using custom - // fragOutputs, they should all be the same for a given shader - bindFragOutputs(shaderProgram->programId(), shader->fragOutputs()); - - const bool linkSucceeded = shaderProgram->link(); - logs += shaderProgram->log(); - - // Perform shader introspection - introspectShaderInterface(shader); - - return {linkSucceeded, logs}; + RHI_UNIMPLEMENTED; + return {true, {}}; +//* QOpenGLShaderProgram *shaderProgram = shader->shaderProgram(); +//* +//* // Compile shaders +//* const auto shaderCode = shader->shaderCode(); +//* +//* QString logs; +//* for (int i = QShaderProgram::Vertex; i <= QShaderProgram::Compute; ++i) { +//* const QShaderProgram::ShaderType type = static_cast<QShaderProgram::ShaderType>(i); +//* if (!shaderCode.at(i).isEmpty()) { +//* // Note: logs only return the error but not all the shader code +//* // we could append it +//* if (!shaderProgram->addCacheableShaderFromSourceCode(shaderType(type), shaderCode.at(i))) +//* logs += shaderProgram->log(); +//* } +//* } +//* +//* // Call glBindFragDataLocation and link the program +//* // Since we are sharing shaders in the backend, we assume that if using custom +//* // fragOutputs, they should all be the same for a given shader +//* bindFragOutputs(shaderProgram->programId(), shader->fragOutputs()); +//* +//* const bool linkSucceeded = shaderProgram->link(); +//* logs += shaderProgram->log(); +//* +//* // Perform shader introspection +//* introspectShaderInterface(shader); +//* +//* return {linkSucceeded, logs}; } // That assumes that the shaderProgram in Shader stays the same void GraphicsContext::introspectShaderInterface(RHIShader *shader) { - QOpenGLShaderProgram *shaderProgram = shader->shaderProgram(); - GraphicsHelperInterface *glHelper = resolveHighestOpenGLFunctions(); - shader->initializeUniforms(glHelper->programUniformsAndLocations(shaderProgram->programId())); - shader->initializeAttributes(glHelper->programAttributesAndLocations(shaderProgram->programId())); - if (m_glHelper->supportsFeature(GraphicsHelperInterface::UniformBufferObject)) - shader->initializeUniformBlocks(m_glHelper->programUniformBlocks(shaderProgram->programId())); - if (m_glHelper->supportsFeature(GraphicsHelperInterface::ShaderStorageObject)) - shader->initializeShaderStorageBlocks(m_glHelper->programShaderStorageBlocks(shaderProgram->programId())); + RHI_UNIMPLEMENTED; +//* QOpenGLShaderProgram *shaderProgram = shader->shaderProgram(); +//* GraphicsHelperInterface *glHelper = resolveHighestOpenGLFunctions(); +//* shader->initializeUniforms(glHelper->programUniformsAndLocations(shaderProgram->programId())); +//* shader->initializeAttributes(glHelper->programAttributesAndLocations(shaderProgram->programId())); +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::UniformBufferObject)) +//* shader->initializeUniformBlocks(m_glHelper->programUniformBlocks(shaderProgram->programId())); +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::ShaderStorageObject)) +//* shader->initializeShaderStorageBlocks(m_glHelper->programShaderStorageBlocks(shaderProgram->programId())); } @@ -285,6 +297,7 @@ void GraphicsContext::loadShader(Shader *shaderNode, ShaderManager *shaderManager, RHIShaderManager *rhiShaderManager) { + RHI_UNIMPLEMENTED; const Qt3DCore::QNodeId shaderId = shaderNode->peerId(); RHIShader *glShader = rhiShaderManager->lookupResource(shaderId); @@ -326,23 +339,25 @@ void GraphicsContext::loadShader(Shader *shaderNode, void GraphicsContext::activateDrawBuffers(const AttachmentPack &attachments) { - const QVector<int> activeDrawBuffers = attachments.getGlDrawBuffers(); - - if (m_glHelper->checkFrameBufferComplete()) { - if (activeDrawBuffers.size() > 1) {// We need MRT - if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT)) { - // Set up MRT, glDrawBuffers... - m_glHelper->drawBuffers(activeDrawBuffers.size(), activeDrawBuffers.data()); - } - } - } else { - qWarning() << "FBO incomplete"; - } + RHI_UNIMPLEMENTED; +//* const QVector<int> activeDrawBuffers = attachments.getGlDrawBuffers(); +//* +//* if (m_glHelper->checkFrameBufferComplete()) { +//* if (activeDrawBuffers.size() > 1) {// We need MRT +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT)) { +//* // Set up MRT, glDrawBuffers... +//* m_glHelper->drawBuffers(activeDrawBuffers.size(), activeDrawBuffers.data()); +//* } +//* } +//* } else { +//* qWarning() << "FBO incomplete"; +//* } } void GraphicsContext::rasterMode(GLenum faceMode, GLenum rasterMode) { - m_glHelper->rasterMode(faceMode, rasterMode); + RHI_UNIMPLEMENTED; +//* m_glHelper->rasterMode(faceMode, rasterMode); } /*! @@ -352,88 +367,91 @@ void GraphicsContext::rasterMode(GLenum faceMode, GLenum rasterMode) */ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions() { - Q_ASSERT(m_gl); - GraphicsHelperInterface *glHelper = nullptr; - - if (m_gl->isOpenGLES()) { - if (m_gl->format().majorVersion() >= 3) { - if (m_gl->format().minorVersion() >= 2) { - glHelper = new GraphicsHelperES3_2; - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES 3.2 Helper"; - } else if (m_gl->format().minorVersion() >= 1) { - glHelper = new GraphicsHelperES3_1; - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES 3.1 Helper"; - } else { - glHelper = new GraphicsHelperES3(); - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES 3.0 Helper"; - } - } else { - glHelper = new GraphicsHelperES2(); - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES2 Helper"; - } - glHelper->initializeHelper(m_gl, nullptr); - } -#ifndef QT_OPENGL_ES_2 - else { - QAbstractOpenGLFunctions *glFunctions = nullptr; - if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_4_3_Core>()) != nullptr) { - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 4.3"; - glHelper = new GraphicsHelperGL4(); - } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_3_3_Core>()) != nullptr) { - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 3.3"; - glHelper = new GraphicsHelperGL3_3(); - } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_3_2_Core>()) != nullptr) { - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 3.2"; - glHelper = new GraphicsHelperGL3_2(); - } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_2_0>()) != nullptr) { - qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 2 Helper"; - glHelper = new GraphicsHelperGL2(); - } - Q_ASSERT_X(glHelper, "GraphicsContext::resolveHighestOpenGLFunctions", "unable to create valid helper for available OpenGL version"); - glHelper->initializeHelper(m_gl, glFunctions); - } -#endif - - // Note: at this point we are certain the context (m_gl) is current with a surface - const QByteArray debugLoggingMode = qgetenv("QT3DRENDER_DEBUG_LOGGING"); - const bool enableDebugLogging = !debugLoggingMode.isEmpty(); - - if (enableDebugLogging && !m_debugLogger) { - if (m_gl->hasExtension("GL_KHR_debug")) { - qCDebug(Backend) << "Qt3D: Enabling OpenGL debug logging"; - m_debugLogger.reset(new QOpenGLDebugLogger); - if (m_debugLogger->initialize()) { - QObject::connect(m_debugLogger.data(), &QOpenGLDebugLogger::messageLogged, &logOpenGLDebugMessage); - const QString mode = QString::fromLocal8Bit(debugLoggingMode); - m_debugLogger->startLogging(mode.startsWith(QLatin1String("sync"), Qt::CaseInsensitive) - ? QOpenGLDebugLogger::SynchronousLogging - : QOpenGLDebugLogger::AsynchronousLogging); - - const auto msgs = m_debugLogger->loggedMessages(); - for (const QOpenGLDebugMessage &msg : msgs) - logOpenGLDebugMessage(msg); - } - } else { - qCDebug(Backend) << "Qt3D: OpenGL debug logging requested but GL_KHR_debug not supported"; - } - } - + RHI_UNIMPLEMENTED; +//* Q_ASSERT(m_gl); +//* GraphicsHelperInterface *glHelper = nullptr; +//* +//* if (m_gl->isOpenGLES()) { +//* if (m_gl->format().majorVersion() >= 3) { +//* if (m_gl->format().minorVersion() >= 2) { +//* glHelper = new GraphicsHelperES3_2; +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES 3.2 Helper"; +//* } else if (m_gl->format().minorVersion() >= 1) { +//* glHelper = new GraphicsHelperES3_1; +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES 3.1 Helper"; +//* } else { +//* glHelper = new GraphicsHelperES3(); +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES 3.0 Helper"; +//* } +//* } else { +//* glHelper = new GraphicsHelperES2(); +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL ES2 Helper"; +//* } +//* glHelper->initializeHelper(m_gl, nullptr); +//* } +//*#ifndef QT_OPENGL_ES_2 +//* else { +//* QAbstractOpenGLFunctions *glFunctions = nullptr; +//* if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_4_3_Core>()) != nullptr) { +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 4.3"; +//* glHelper = new GraphicsHelperGL4(); +//* } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_3_3_Core>()) != nullptr) { +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 3.3"; +//* glHelper = new GraphicsHelperGL3_3(); +//* } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_3_2_Core>()) != nullptr) { +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 3.2"; +//* glHelper = new GraphicsHelperGL3_2(); +//* } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_2_0>()) != nullptr) { +//* qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 2 Helper"; +//* glHelper = new GraphicsHelperGL2(); +//* } +//* Q_ASSERT_X(glHelper, "GraphicsContext::resolveHighestOpenGLFunctions", "unable to create valid helper for available OpenGL version"); +//* glHelper->initializeHelper(m_gl, glFunctions); +//* } +//*#endif +//* +//* // Note: at this point we are certain the context (m_gl) is current with a surface +//* const QByteArray debugLoggingMode = qgetenv("QT3DRENDER_DEBUG_LOGGING"); +//* const bool enableDebugLogging = !debugLoggingMode.isEmpty(); +//* +//* if (enableDebugLogging && !m_debugLogger) { +//* if (m_gl->hasExtension("GL_KHR_debug")) { +//* qCDebug(Backend) << "Qt3D: Enabling OpenGL debug logging"; +//* m_debugLogger.reset(new QOpenGLDebugLogger); +//* if (m_debugLogger->initialize()) { +//* QObject::connect(m_debugLogger.data(), &QOpenGLDebugLogger::messageLogged, &logOpenGLDebugMessage); +//* const QString mode = QString::fromLocal8Bit(debugLoggingMode); +//* m_debugLogger->startLogging(mode.startsWith(QLatin1String("sync"), Qt::CaseInsensitive) +//* ? QOpenGLDebugLogger::SynchronousLogging +//* : QOpenGLDebugLogger::AsynchronousLogging); +//* +//* const auto msgs = m_debugLogger->loggedMessages(); +//* for (const QOpenGLDebugMessage &msg : msgs) +//* logOpenGLDebugMessage(msg); +//* } +//* } else { +//* qCDebug(Backend) << "Qt3D: OpenGL debug logging requested but GL_KHR_debug not supported"; +//* } +//* } +//* // Set Vendor and Extensions of reference GraphicsApiFilter // TO DO: would that vary like the glHelper ? QStringList extensions; - const auto exts = m_gl->extensions(); - for (const QByteArray &ext : exts) - extensions << QString::fromUtf8(ext); - m_contextInfo.m_major = m_gl->format().version().first; - m_contextInfo.m_minor = m_gl->format().version().second; - m_contextInfo.m_api = m_gl->isOpenGLES() ? QGraphicsApiFilter::OpenGLES : QGraphicsApiFilter::OpenGL; - m_contextInfo.m_profile = static_cast<QGraphicsApiFilter::OpenGLProfile>(m_gl->format().profile()); + //const auto exts = m_gl->extensions(); + //for (const QByteArray &ext : exts) + // extensions << QString::fromUtf8(ext); + m_contextInfo.m_major = 3; + m_contextInfo.m_minor = 2; + // m_contextInfo.m_major = m_gl->format().version().first; + // m_contextInfo.m_minor = m_gl->format().version().second; + m_contextInfo.m_api = QGraphicsApiFilter::RHI; + //m_contextInfo.m_profile = static_cast<QGraphicsApiFilter::OpenGLProfile>(m_gl->format().profile()); m_contextInfo.m_extensions = extensions; - m_contextInfo.m_vendor = QString::fromUtf8(reinterpret_cast<const char *>(m_gl->functions()->glGetString(GL_VENDOR))); + //m_contextInfo.m_vendor = QString::fromUtf8(reinterpret_cast<const char *>(m_gl->functions()->glGetString(GL_VENDOR))); - return glHelper; + return nullptr; } const GraphicsApiFilterData *GraphicsContext::contextInfo() const @@ -443,7 +461,8 @@ const GraphicsApiFilterData *GraphicsContext::contextInfo() const bool GraphicsContext::supportsDrawBuffersBlend() const { - return m_glHelper->supportsFeature(GraphicsHelperInterface::DrawBuffersBlend); + return false; +//* return m_glHelper->supportsFeature(GraphicsHelperInterface::DrawBuffersBlend); } /*! @@ -460,13 +479,14 @@ void GraphicsContext::drawElementsInstancedBaseVertexBaseInstance(GLenum primiti GLint baseVertex, GLint baseInstance) { - m_glHelper->drawElementsInstancedBaseVertexBaseInstance(primitiveType, - primitiveCount, - indexType, - indices, - instances, - baseVertex, - baseInstance); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawElementsInstancedBaseVertexBaseInstance(primitiveType, +//* primitiveCount, +//* indexType, +//* indices, +//* instances, +//* baseVertex, +//* baseInstance); } /*! @@ -478,19 +498,21 @@ void GraphicsContext::drawArraysInstanced(GLenum primitiveType, GLsizei count, GLsizei instances) { - m_glHelper->drawArraysInstanced(primitiveType, - first, - count, - instances); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawArraysInstanced(primitiveType, +//* first, +//* count, +//* instances); } void GraphicsContext::drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseinstance) { - m_glHelper->drawArraysInstancedBaseInstance(primitiveType, - first, - count, - instances, - baseinstance); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawArraysInstancedBaseInstance(primitiveType, +//* first, +//* count, +//* instances, +//* baseinstance); } /*! @@ -503,18 +525,20 @@ void GraphicsContext::drawElements(GLenum primitiveType, void *indices, GLint baseVertex) { - m_glHelper->drawElements(primitiveType, - primitiveCount, - indexType, - indices, - baseVertex); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawElements(primitiveType, +//* primitiveCount, +//* indexType, +//* indices, +//* baseVertex); } void GraphicsContext::drawElementsIndirect(GLenum mode, GLenum type, void *indirect) { - m_glHelper->drawElementsIndirect(mode, type, indirect); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawElementsIndirect(mode, type, indirect); } /*! @@ -525,350 +549,398 @@ void GraphicsContext::drawArrays(GLenum primitiveType, GLint first, GLsizei count) { - m_glHelper->drawArrays(primitiveType, - first, - count); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawArrays(primitiveType, +//* first, +//* count); } void GraphicsContext::drawArraysIndirect(GLenum mode, void *indirect) { - m_glHelper->drawArraysIndirect(mode, indirect); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawArraysIndirect(mode, indirect); } void GraphicsContext::setVerticesPerPatch(GLint verticesPerPatch) { - m_glHelper->setVerticesPerPatch(verticesPerPatch); + RHI_UNIMPLEMENTED; +//* m_glHelper->setVerticesPerPatch(verticesPerPatch); } void GraphicsContext::blendEquation(GLenum mode) { - m_glHelper->blendEquation(mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->blendEquation(mode); } void GraphicsContext::blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) { - m_glHelper->blendFunci(buf, sfactor, dfactor); + RHI_UNIMPLEMENTED; +//* m_glHelper->blendFunci(buf, sfactor, dfactor); } void GraphicsContext::blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) { - m_glHelper->blendFuncSeparatei(buf, sRGB, dRGB, sAlpha, dAlpha); + RHI_UNIMPLEMENTED; +//* m_glHelper->blendFuncSeparatei(buf, sRGB, dRGB, sAlpha, dAlpha); } void GraphicsContext::alphaTest(GLenum mode1, GLenum mode2) { - m_glHelper->alphaTest(mode1, mode2); + RHI_UNIMPLEMENTED; +//* m_glHelper->alphaTest(mode1, mode2); } void GraphicsContext::bindFramebuffer(GLuint fbo, GraphicsHelperInterface::FBOBindMode mode) { - m_glHelper->bindFrameBufferObject(fbo, mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->bindFrameBufferObject(fbo, mode); } void GraphicsContext::depthRange(GLdouble nearValue, GLdouble farValue) { - m_glHelper->depthRange(nearValue, farValue); + RHI_UNIMPLEMENTED; +//* m_glHelper->depthRange(nearValue, farValue); } void GraphicsContext::depthTest(GLenum mode) { - m_glHelper->depthTest(mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->depthTest(mode); } void GraphicsContext::depthMask(GLenum mode) { - m_glHelper->depthMask(mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->depthMask(mode); } void GraphicsContext::frontFace(GLenum mode) { - m_glHelper->frontFace(mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->frontFace(mode); } void GraphicsContext::bindFragOutputs(GLuint shader, const QHash<QString, int> &outputs) { - if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT) && - m_glHelper->supportsFeature(GraphicsHelperInterface::BindableFragmentOutputs)) - m_glHelper->bindFragDataLocation(shader, outputs); + RHI_UNIMPLEMENTED; +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT) && +//* m_glHelper->supportsFeature(GraphicsHelperInterface::BindableFragmentOutputs)) +//* m_glHelper->bindFragDataLocation(shader, outputs); } void GraphicsContext::bindImageTexture(GLuint imageUnit, GLuint texture, GLint mipLevel, GLboolean layered, GLint layer, GLenum access, GLenum format) { - m_glHelper->bindImageTexture(imageUnit, - texture, - mipLevel, - layered, - layer, - access, - format); + RHI_UNIMPLEMENTED; +//* m_glHelper->bindImageTexture(imageUnit, +//* texture, +//* mipLevel, +//* layered, +//* layer, +//* access, +//* format); } void GraphicsContext::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { - m_glHelper->bindUniformBlock(programId, uniformBlockIndex, uniformBlockBinding); + RHI_UNIMPLEMENTED; +//* m_glHelper->bindUniformBlock(programId, uniformBlockIndex, uniformBlockBinding); } void GraphicsContext::bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) { - m_glHelper->bindShaderStorageBlock(programId, shaderStorageBlockIndex, shaderStorageBlockBinding); + RHI_UNIMPLEMENTED; +//* m_glHelper->bindShaderStorageBlock(programId, shaderStorageBlockIndex, shaderStorageBlockBinding); } void GraphicsContext::bindBufferBase(GLenum target, GLuint bindingIndex, GLuint buffer) { - m_glHelper->bindBufferBase(target, bindingIndex, buffer); + RHI_UNIMPLEMENTED; +//* m_glHelper->bindBufferBase(target, bindingIndex, buffer); } void GraphicsContext::buildUniformBuffer(const QVariant &v, const ShaderUniform &description, QByteArray &buffer) { - m_glHelper->buildUniformBuffer(v, description, buffer); + RHI_UNIMPLEMENTED; +//* m_glHelper->buildUniformBuffer(v, description, buffer); } void GraphicsContext::setMSAAEnabled(bool enabled) { - m_glHelper->setMSAAEnabled(enabled); + RHI_UNIMPLEMENTED; +//* m_glHelper->setMSAAEnabled(enabled); } void GraphicsContext::setAlphaCoverageEnabled(bool enabled) { - m_glHelper->setAlphaCoverageEnabled(enabled); + RHI_UNIMPLEMENTED; +//* m_glHelper->setAlphaCoverageEnabled(enabled); } void GraphicsContext::clearBufferf(GLint drawbuffer, const QVector4D &values) { - m_glHelper->clearBufferf(drawbuffer, values); + RHI_UNIMPLEMENTED; +//* m_glHelper->clearBufferf(drawbuffer, values); } GLuint GraphicsContext::boundFrameBufferObject() { - return m_glHelper->boundFrameBufferObject(); + RHI_UNIMPLEMENTED; + return false; +//* return m_glHelper->boundFrameBufferObject(); } void GraphicsContext::clearColor(const QColor &color) { - m_gl->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); + RHI_UNIMPLEMENTED; +//* m_gl->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); } void GraphicsContext::clearDepthValue(float depth) { - m_gl->functions()->glClearDepthf(depth); + RHI_UNIMPLEMENTED; +//* m_gl->functions()->glClearDepthf(depth); } void GraphicsContext::clearStencilValue(int stencil) { - m_gl->functions()->glClearStencil(stencil); + RHI_UNIMPLEMENTED; +//* m_gl->functions()->glClearStencil(stencil); } void GraphicsContext::enableClipPlane(int clipPlane) { - m_glHelper->enableClipPlane(clipPlane); + RHI_UNIMPLEMENTED; +//* m_glHelper->enableClipPlane(clipPlane); } void GraphicsContext::disableClipPlane(int clipPlane) { - m_glHelper->disableClipPlane(clipPlane); + RHI_UNIMPLEMENTED; +//* m_glHelper->disableClipPlane(clipPlane); } void GraphicsContext::setClipPlane(int clipPlane, const QVector3D &normal, float distance) { - m_glHelper->setClipPlane(clipPlane, normal, distance); + RHI_UNIMPLEMENTED; +//* m_glHelper->setClipPlane(clipPlane, normal, distance); } GLint GraphicsContext::maxClipPlaneCount() { - return m_glHelper->maxClipPlaneCount(); + RHI_UNIMPLEMENTED; +//* return m_glHelper->maxClipPlaneCount(); } GLint GraphicsContext::maxTextureUnitsCount() const { - return m_maxTextureUnits; + RHI_UNIMPLEMENTED; +//* return m_maxTextureUnits; } GLint GraphicsContext::maxImageUnitsCount() const { - return m_maxImageUnits; + RHI_UNIMPLEMENTED; +//* return m_maxImageUnits; } void GraphicsContext::enablePrimitiveRestart(int restartIndex) { - if (m_glHelper->supportsFeature(GraphicsHelperInterface::PrimitiveRestart)) - m_glHelper->enablePrimitiveRestart(restartIndex); + RHI_UNIMPLEMENTED; +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::PrimitiveRestart)) +//* m_glHelper->enablePrimitiveRestart(restartIndex); } void GraphicsContext::disablePrimitiveRestart() { - if (m_glHelper->supportsFeature(GraphicsHelperInterface::PrimitiveRestart)) - m_glHelper->disablePrimitiveRestart(); + RHI_UNIMPLEMENTED; +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::PrimitiveRestart)) +//* m_glHelper->disablePrimitiveRestart(); } void GraphicsContext::pointSize(bool programmable, GLfloat value) { - m_glHelper->pointSize(programmable, value); + RHI_UNIMPLEMENTED; +//* m_glHelper->pointSize(programmable, value); } void GraphicsContext::dispatchCompute(int x, int y, int z) { - if (m_glHelper->supportsFeature(GraphicsHelperInterface::Compute)) - m_glHelper->dispatchCompute(x, y, z); + RHI_UNIMPLEMENTED; +//* if (m_glHelper->supportsFeature(GraphicsHelperInterface::Compute)) +//* m_glHelper->dispatchCompute(x, y, z); } GLboolean GraphicsContext::unmapBuffer(GLenum target) { - return m_glHelper->unmapBuffer(target); + RHI_UNIMPLEMENTED; + return true; +//* return m_glHelper->unmapBuffer(target); } char *GraphicsContext::mapBuffer(GLenum target, GLsizeiptr size) { - return m_glHelper->mapBuffer(target, size); + RHI_UNIMPLEMENTED; + return nullptr; +//* return m_glHelper->mapBuffer(target, size); } void GraphicsContext::enablei(GLenum cap, GLuint index) { - m_glHelper->enablei(cap, index); + RHI_UNIMPLEMENTED; +//* m_glHelper->enablei(cap, index); } void GraphicsContext::disablei(GLenum cap, GLuint index) { - m_glHelper->disablei(cap, index); + RHI_UNIMPLEMENTED; +//* m_glHelper->disablei(cap, index); } void GraphicsContext::setSeamlessCubemap(bool enable) { - m_glHelper->setSeamlessCubemap(enable); + RHI_UNIMPLEMENTED; +//* m_glHelper->setSeamlessCubemap(enable); } void GraphicsContext::readBuffer(GLenum mode) { - m_glHelper->readBuffer(mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->readBuffer(mode); } void GraphicsContext::drawBuffer(GLenum mode) { - m_glHelper->drawBuffer(mode); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawBuffer(mode); } void GraphicsContext::drawBuffers(GLsizei n, const int *bufs) { - m_glHelper->drawBuffers(n, bufs); + RHI_UNIMPLEMENTED; +//* m_glHelper->drawBuffers(n, bufs); } void GraphicsContext::applyUniform(const ShaderUniform &description, const UniformValue &v) { - const UniformType type = m_glHelper->uniformTypeFromGLType(description.m_type); - - switch (type) { - case UniformType::Float: - // See QTBUG-57510 and uniform_p.h - if (v.storedType() == Int) { - float value = float(*v.constData<int>()); - UniformValue floatV(value); - applyUniformHelper<UniformType::Float>(description, floatV); - } else { - applyUniformHelper<UniformType::Float>(description, v); - } - break; - case UniformType::Vec2: - applyUniformHelper<UniformType::Vec2>(description, v); - break; - case UniformType::Vec3: - applyUniformHelper<UniformType::Vec3>(description, v); - break; - case UniformType::Vec4: - applyUniformHelper<UniformType::Vec4>(description, v); - break; - - case UniformType::Double: - applyUniformHelper<UniformType::Double>(description, v); - break; - case UniformType::DVec2: - applyUniformHelper<UniformType::DVec2>(description, v); - break; - case UniformType::DVec3: - applyUniformHelper<UniformType::DVec3>(description, v); - break; - case UniformType::DVec4: - applyUniformHelper<UniformType::DVec4>(description, v); - break; - - case UniformType::Sampler: - case UniformType::Image: - case UniformType::Int: - applyUniformHelper<UniformType::Int>(description, v); - break; - case UniformType::IVec2: - applyUniformHelper<UniformType::IVec2>(description, v); - break; - case UniformType::IVec3: - applyUniformHelper<UniformType::IVec3>(description, v); - break; - case UniformType::IVec4: - applyUniformHelper<UniformType::IVec4>(description, v); - break; - - case UniformType::UInt: - applyUniformHelper<UniformType::UInt>(description, v); - break; - case UniformType::UIVec2: - applyUniformHelper<UniformType::UIVec2>(description, v); - break; - case UniformType::UIVec3: - applyUniformHelper<UniformType::UIVec3>(description, v); - break; - case UniformType::UIVec4: - applyUniformHelper<UniformType::UIVec4>(description, v); - break; - - case UniformType::Bool: - applyUniformHelper<UniformType::Bool>(description, v); - break; - case UniformType::BVec2: - applyUniformHelper<UniformType::BVec2>(description, v); - break; - case UniformType::BVec3: - applyUniformHelper<UniformType::BVec3>(description, v); - break; - case UniformType::BVec4: - applyUniformHelper<UniformType::BVec4>(description, v); - break; - - case UniformType::Mat2: - applyUniformHelper<UniformType::Mat2>(description, v); - break; - case UniformType::Mat3: - applyUniformHelper<UniformType::Mat3>(description, v); - break; - case UniformType::Mat4: - applyUniformHelper<UniformType::Mat4>(description, v); - break; - case UniformType::Mat2x3: - applyUniformHelper<UniformType::Mat2x3>(description, v); - break; - case UniformType::Mat3x2: - applyUniformHelper<UniformType::Mat3x2>(description, v); - break; - case UniformType::Mat2x4: - applyUniformHelper<UniformType::Mat2x4>(description, v); - break; - case UniformType::Mat4x2: - applyUniformHelper<UniformType::Mat4x2>(description, v); - break; - case UniformType::Mat3x4: - applyUniformHelper<UniformType::Mat3x4>(description, v); - break; - case UniformType::Mat4x3: - applyUniformHelper<UniformType::Mat4x3>(description, v); - break; - - default: - break; - } + RHI_UNIMPLEMENTED; + //* const UniformType type = m_glHelper->uniformTypeFromGLType(description.m_type); + //* + //* switch (type) { + //* case UniformType::Float: + //* // See QTBUG-57510 and uniform_p.h + //* if (v.storedType() == Int) { + //* float value = float(*v.constData<int>()); + //* UniformValue floatV(value); + //* applyUniformHelper<UniformType::Float>(description, floatV); + //* } else { + //* applyUniformHelper<UniformType::Float>(description, v); + //* } + //* break; + //* case UniformType::Vec2: + //* applyUniformHelper<UniformType::Vec2>(description, v); + //* break; + //* case UniformType::Vec3: + //* applyUniformHelper<UniformType::Vec3>(description, v); + //* break; + //* case UniformType::Vec4: + //* applyUniformHelper<UniformType::Vec4>(description, v); + //* break; + //* + //* case UniformType::Double: + //* applyUniformHelper<UniformType::Double>(description, v); + //* break; + //* case UniformType::DVec2: + //* applyUniformHelper<UniformType::DVec2>(description, v); + //* break; + //* case UniformType::DVec3: + //* applyUniformHelper<UniformType::DVec3>(description, v); + //* break; + //* case UniformType::DVec4: + //* applyUniformHelper<UniformType::DVec4>(description, v); + //* break; + //* + //* case UniformType::Sampler: + //* case UniformType::Image: + //* case UniformType::Int: + //* applyUniformHelper<UniformType::Int>(description, v); + //* break; + //* case UniformType::IVec2: + //* applyUniformHelper<UniformType::IVec2>(description, v); + //* break; + //* case UniformType::IVec3: + //* applyUniformHelper<UniformType::IVec3>(description, v); + //* break; + //* case UniformType::IVec4: + //* applyUniformHelper<UniformType::IVec4>(description, v); + //* break; + //* + //* case UniformType::UInt: + //* applyUniformHelper<UniformType::UInt>(description, v); + //* break; + //* case UniformType::UIVec2: + //* applyUniformHelper<UniformType::UIVec2>(description, v); + //* break; + //* case UniformType::UIVec3: + //* applyUniformHelper<UniformType::UIVec3>(description, v); + //* break; + //* case UniformType::UIVec4: + //* applyUniformHelper<UniformType::UIVec4>(description, v); + //* break; + //* + //* case UniformType::Bool: + //* applyUniformHelper<UniformType::Bool>(description, v); + //* break; + //* case UniformType::BVec2: + //* applyUniformHelper<UniformType::BVec2>(description, v); + //* break; + //* case UniformType::BVec3: + //* applyUniformHelper<UniformType::BVec3>(description, v); + //* break; + //* case UniformType::BVec4: + //* applyUniformHelper<UniformType::BVec4>(description, v); + //* break; + //* + //* case UniformType::Mat2: + //* applyUniformHelper<UniformType::Mat2>(description, v); + //* break; + //* case UniformType::Mat3: + //* applyUniformHelper<UniformType::Mat3>(description, v); + //* break; + //* case UniformType::Mat4: + //* applyUniformHelper<UniformType::Mat4>(description, v); + //* break; + //* case UniformType::Mat2x3: + //* applyUniformHelper<UniformType::Mat2x3>(description, v); + //* break; + //* case UniformType::Mat3x2: + //* applyUniformHelper<UniformType::Mat3x2>(description, v); + //* break; + //* case UniformType::Mat2x4: + //* applyUniformHelper<UniformType::Mat2x4>(description, v); + //* break; + //* case UniformType::Mat4x2: + //* applyUniformHelper<UniformType::Mat4x2>(description, v); + //* break; + //* case UniformType::Mat3x4: + //* applyUniformHelper<UniformType::Mat3x4>(description, v); + //* break; + //* case UniformType::Mat4x3: + //* applyUniformHelper<UniformType::Mat4x3>(description, v); + //* break; + //* + //* default: + //* break; + //* } } void GraphicsContext::memoryBarrier(QMemoryBarrier::Operations barriers) { - m_glHelper->memoryBarrier(barriers); + RHI_UNIMPLEMENTED; + //* m_glHelper->memoryBarrier(barriers); } GLint GraphicsContext::elementType(GLint type) diff --git a/src/plugins/renderers/rhi/graphicshelpers/graphicscontext_p.h b/src/plugins/renderers/rhi/graphicshelpers/graphicscontext_p.h index 0583e3f11..89da47371 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/graphicscontext_p.h +++ b/src/plugins/renderers/rhi/graphicshelpers/graphicscontext_p.h @@ -80,6 +80,10 @@ class QOpenGLShaderProgram; class QAbstractOpenGLFunctions; class QOpenGLDebugLogger; +class QRhi; +class QRhiSwapChain; +class QRhiResourceUpdateBatch; + namespace Qt3DRender { namespace Render { @@ -93,7 +97,6 @@ namespace Rhi { class GraphicsHelperInterface; class RHIShader; class RHIShaderManager; - typedef QPair<QString, int> NamedUniformLocation; class Q_AUTOTEST_EXPORT GraphicsContext @@ -103,7 +106,7 @@ public: ~GraphicsContext(); void setOpenGLContext(QOpenGLContext* ctx); - QOpenGLContext *openGLContext() { return m_gl; } + //QOpenGLContext *openGLContext() { return m_gl; } bool makeCurrent(QSurface *surface); void doneCurrent(); bool hasValidGLHelper() const; @@ -196,16 +199,20 @@ public: GLint m_maxTextureUnits; GLint m_maxImageUnits; GLuint m_defaultFBO; - QOpenGLContext *m_gl; - GraphicsHelperInterface *m_glHelper; + //* QOpenGLContext *m_gl; + //* GraphicsHelperInterface *m_glHelper; - QHash<QSurface *, GraphicsHelperInterface*> m_glHelpers; + //* QHash<QSurface *, GraphicsHelperInterface*> m_glHelpers; GraphicsApiFilterData m_contextInfo; QScopedPointer<QOpenGLDebugLogger> m_debugLogger; friend class RHIVertexArrayObject; RHIVertexArrayObject *m_currentVAO; + QRhi* m_rhi{}; + QRhiSwapChain* m_sc{}; + QRhiResourceUpdateBatch *m_currentUpdates{}; + void applyUniform(const ShaderUniform &description, const UniformValue &v); template<UniformType> @@ -223,8 +230,8 @@ void GraphicsContext::applyUniformHelper<UniformTypeEnum>(const ShaderUniform &d template<> \ void GraphicsContext::applyUniformHelper<UniformTypeEnum>(const ShaderUniform &description, const UniformValue &value) const \ { \ - const int count = qMin(description.m_size, int(value.byteSize() / description.m_rawByteSize)); \ - m_glHelper->Func(description.m_location, count, value.constData<BaseType>()); \ + /*/ const int count = qMin(description.m_size, int(value.byteSize() / description.m_rawByteSize)); \ + m_glHelper->Func(description.m_location, count, value.constData<BaseType>()); */ \ } diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp index f7ba1815d..23c1dcb33 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp @@ -159,6 +159,7 @@ void copyGLFramebufferDataToImage(QImage &img, const uchar *srcData, uint stride } // Render States Helpers +/* template<typename GenericState> void applyStateHelper(const GenericState *state, SubmissionContext *gc) { @@ -355,7 +356,7 @@ void applyStateHelper<LineWidth>(const LineWidth *state, SubmissionContext *gc) gc->openGLContext()->functions()->glLineWidth(std::get<0>(values)); } - +*/ } // anonymous @@ -371,7 +372,6 @@ SubmissionContext::SubmissionContext() , m_currClearColorValue(0,0,0,0) , m_material(nullptr) , m_activeFBO(0) - , m_boundArrayBuffer(nullptr) , m_stateSet(nullptr) , m_renderer(nullptr) , m_uboTempArray(QByteArray(1024, 0)) @@ -396,33 +396,35 @@ void SubmissionContext::initialize() void SubmissionContext::resolveRenderTargetFormat() { - const QSurfaceFormat format = m_gl->format(); - const uint a = (format.alphaBufferSize() == -1) ? 0 : format.alphaBufferSize(); - const uint r = format.redBufferSize(); - const uint g = format.greenBufferSize(); - const uint b = format.blueBufferSize(); - -#define RGBA_BITS(r,g,b,a) (r | (g << 6) | (b << 12) | (a << 18)) - - const uint bits = RGBA_BITS(r,g,b,a); - switch (bits) { - case RGBA_BITS(8,8,8,8): - m_renderTargetFormat = QAbstractTexture::RGBA8_UNorm; - break; - case RGBA_BITS(8,8,8,0): - m_renderTargetFormat = QAbstractTexture::RGB8_UNorm; - break; - case RGBA_BITS(5,6,5,0): - m_renderTargetFormat = QAbstractTexture::R5G6B5; - break; - } -#undef RGBA_BITS + RHI_UNIMPLEMENTED; + +//* const QSurfaceFormat format = m_gl->format(); +//* const uint a = (format.alphaBufferSize() == -1) ? 0 : format.alphaBufferSize(); +//* const uint r = format.redBufferSize(); +//* const uint g = format.greenBufferSize(); +//* const uint b = format.blueBufferSize(); +//* +//* #define RGBA_BITS(r,g,b,a) (r | (g << 6) | (b << 12) | (a << 18)) +//* +//* const uint bits = RGBA_BITS(r,g,b,a); +//* switch (bits) { +//* case RGBA_BITS(8,8,8,8): +//* m_renderTargetFormat = QAbstractTexture::RGBA8_UNorm; +//* break; +//* case RGBA_BITS(8,8,8,0): +//* m_renderTargetFormat = QAbstractTexture::RGB8_UNorm; +//* break; +//* case RGBA_BITS(5,6,5,0): +//* m_renderTargetFormat = QAbstractTexture::R5G6B5; +//* break; +//* } +//* #undef RGBA_BITS } bool SubmissionContext::beginDrawing(QSurface *surface) { Q_ASSERT(surface); - Q_ASSERT(m_gl); +//* Q_ASSERT(m_gl); m_surface = surface; @@ -436,9 +438,9 @@ bool SubmissionContext::beginDrawing(QSurface *surface) // Makes the surface current on the OpenGLContext // and sets the right glHelper - m_ownCurrent = !(m_gl->surface() == m_surface); - if (m_ownCurrent && !makeCurrent(m_surface)) - return false; + // m_ownCurrent = !(m_gl->surface() == m_surface); + // if (m_ownCurrent && !makeCurrent(m_surface)) + // return false; // TODO: cache surface format somewhere rather than doing this every time render surface changes resolveRenderTargetFormat(); @@ -452,33 +454,41 @@ bool SubmissionContext::beginDrawing(QSurface *surface) if (!isInitialized()) initialize(); - initializeHelpers(m_surface); + // initializeHelpers(m_surface); // need to reset these values every frame, may get overwritten elsewhere - m_gl->functions()->glClearColor(m_currClearColorValue.redF(), m_currClearColorValue.greenF(), m_currClearColorValue.blueF(), m_currClearColorValue.alphaF()); - m_gl->functions()->glClearDepthf(m_currClearDepthValue); - m_gl->functions()->glClearStencil(m_currClearStencilValue); + RHI_UNIMPLEMENTED; +//* m_gl->functions()->glClearColor(m_currClearColorValue.redF(), m_currClearColorValue.greenF(), m_currClearColorValue.blueF(), m_currClearColorValue.alphaF()); +//* m_gl->functions()->glClearDepthf(m_currClearDepthValue); +//* m_gl->functions()->glClearStencil(m_currClearStencilValue); if (m_activeShader) { m_activeShader = nullptr; } - m_boundArrayBuffer = nullptr; + + m_rhi->beginFrame(m_sc); return true; } void SubmissionContext::endDrawing(bool swapBuffers) { - if (swapBuffers) - m_gl->swapBuffers(m_surface); - if (m_ownCurrent) - m_gl->doneCurrent(); + m_rhi->endFrame(m_sc, {}); + RHI_UNIMPLEMENTED; +//* if (swapBuffers) +//* m_gl->swapBuffers(m_surface); +//* if (m_ownCurrent) +//* m_gl->doneCurrent(); m_textureContext.endDrawing(); m_imageContext.endDrawing(); +//* static int i = 0; +//* if(i++ == 10) +//* std::exit(0); } void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments, GLuint defaultFboId) { + RHI_UNIMPLEMENTED; GLuint fboId = defaultFboId; // Default FBO if (renderTargetNodeId) { // New RenderTarget @@ -488,246 +498,256 @@ void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeI // Insert FBO into hash m_renderTargets.insert(renderTargetNodeId, fboId); } else { + RHI_UNIMPLEMENTED; fboId = createRenderTarget(renderTargetNodeId, attachments); } } else { + RHI_UNIMPLEMENTED; fboId = updateRenderTarget(renderTargetNodeId, attachments, true); } } m_activeFBO = fboId; - m_glHelper->bindFrameBufferObject(m_activeFBO, GraphicsHelperInterface::FBODraw); +//* m_glHelper->bindFrameBufferObject(m_activeFBO, GraphicsHelperInterface::FBODraw); // Set active drawBuffers activateDrawBuffers(attachments); } GLuint SubmissionContext::createRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments) { - const GLuint fboId = m_glHelper->createFrameBufferObject(); - if (fboId) { - // The FBO is created and its attachments are set once - // Insert FBO into hash - m_renderTargets.insert(renderTargetNodeId, fboId); - // Bind FBO - m_glHelper->bindFrameBufferObject(fboId, GraphicsHelperInterface::FBODraw); - bindFrameBufferAttachmentHelper(fboId, attachments); - } else { - qCritical("Failed to create FBO"); - } - return fboId; + RHI_UNIMPLEMENTED; + return 0; +//* const GLuint fboId = m_glHelper->createFrameBufferObject(); +//* if (fboId) { +//* // The FBO is created and its attachments are set once +//* // Insert FBO into hash +//* m_renderTargets.insert(renderTargetNodeId, fboId); +//* // Bind FBO +//* m_glHelper->bindFrameBufferObject(fboId, GraphicsHelperInterface::FBODraw); +//* bindFrameBufferAttachmentHelper(fboId, attachments); +//* } else { +//* qCritical("Failed to create FBO"); +//* } +//* return fboId; } GLuint SubmissionContext::updateRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments, bool isActiveRenderTarget) { - const GLuint fboId = m_renderTargets.value(renderTargetNodeId); - - // We need to check if one of the attachment was resized - bool needsResize = !m_renderTargetsSize.contains(fboId); // not even initialized yet? - if (!needsResize) { - // render target exists, has attachment been resized? - RHITextureManager *rhiTextureManager = m_renderer->rhiResourceManagers()->rhiTextureManager(); - const QSize s = m_renderTargetsSize[fboId]; - const auto attachments_ = attachments.attachments(); - for (const Attachment &attachment : attachments_) { - RHITexture *rTex = rhiTextureManager->lookupResource(attachment.m_textureUuid); - // ### TODO QTBUG-64757 this check is insufficient since the - // texture may have changed to another one with the same size. That - // case is not handled atm. - if (rTex) { - needsResize |= rTex->size() != s; - if (isActiveRenderTarget && attachment.m_point == QRenderTargetOutput::Color0) - m_renderTargetFormat = rTex->properties().format; - } - } - } - - if (needsResize) { - m_glHelper->bindFrameBufferObject(fboId, GraphicsHelperInterface::FBODraw); - bindFrameBufferAttachmentHelper(fboId, attachments); - } - - return fboId; + RHI_UNIMPLEMENTED; + return 0; +//* const GLuint fboId = m_renderTargets.value(renderTargetNodeId); +//* +//* // We need to check if one of the attachment was resized +//* bool needsResize = !m_renderTargetsSize.contains(fboId); // not even initialized yet? +//* if (!needsResize) { +//* // render target exists, has attachment been resized? +//* RHITextureManager *rhiTextureManager = m_renderer->rhiResourceManagers()->rhiTextureManager(); +//* const QSize s = m_renderTargetsSize[fboId]; +//* const auto attachments_ = attachments.attachments(); +//* for (const Attachment &attachment : attachments_) { +//* RHITexture *rTex = rhiTextureManager->lookupResource(attachment.m_textureUuid); +//* // ### TODO QTBUG-64757 this check is insufficient since the +//* // texture may have changed to another one with the same size. That +//* // case is not handled atm. +//* if (rTex) { +//* needsResize |= rTex->size() != s; +//* if (isActiveRenderTarget && attachment.m_point == QRenderTargetOutput::Color0) +//* m_renderTargetFormat = rTex->properties().format; +//* } +//* } +//* } +//* +//* if (needsResize) { +//* m_glHelper->bindFrameBufferObject(fboId, GraphicsHelperInterface::FBODraw); +//* bindFrameBufferAttachmentHelper(fboId, attachments); +//* } +//* +//* return fboId; } QSize SubmissionContext::renderTargetSize(const QSize &surfaceSize) const { - QSize renderTargetSize; - if (m_activeFBO != m_defaultFBO) { - // For external FBOs we may not have a m_renderTargets entry. - if (m_renderTargetsSize.contains(m_activeFBO)) { - renderTargetSize = m_renderTargetsSize[m_activeFBO]; - } else if (surfaceSize.isValid()) { - renderTargetSize = surfaceSize; - } else { - // External FBO (when used with QtQuick2 Scene3D) - - // Query FBO color attachment 0 size - GLint attachmentObjectType = GL_NONE; - GLint attachment0Name = 0; - m_gl->functions()->glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, - &attachmentObjectType); - m_gl->functions()->glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, - GL_COLOR_ATTACHMENT0, - GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, - &attachment0Name); - - if (attachmentObjectType == GL_RENDERBUFFER && m_glHelper->supportsFeature(GraphicsHelperInterface::RenderBufferDimensionRetrieval)) - renderTargetSize = m_glHelper->getRenderBufferDimensions(attachment0Name); - else if (attachmentObjectType == GL_TEXTURE && m_glHelper->supportsFeature(GraphicsHelperInterface::TextureDimensionRetrieval)) - // Assumes texture level 0 and GL_TEXTURE_2D target - renderTargetSize = m_glHelper->getTextureDimensions(attachment0Name, GL_TEXTURE_2D); - else - return renderTargetSize; - } - } else { - renderTargetSize = m_surface->size(); - if (m_surface->surfaceClass() == QSurface::Window) { - const float dpr = static_cast<QWindow *>(m_surface)->devicePixelRatio(); - renderTargetSize *= dpr; - } - } - return renderTargetSize; + RHI_UNIMPLEMENTED; + return surfaceSize; +//* QSize renderTargetSize{}; +//* if (m_activeFBO != m_defaultFBO) { +//* // For external FBOs we may not have a m_renderTargets entry. +//* if (m_renderTargetsSize.contains(m_activeFBO)) { +//* renderTargetSize = m_renderTargetsSize[m_activeFBO]; +//* } else if (surfaceSize.isValid()) { +//* renderTargetSize = surfaceSize; +//* } else { +//* // External FBO (when used with QtQuick2 Scene3D) +//* +//* // Query FBO color attachment 0 size +//* GLint attachmentObjectType = GL_NONE; +//* GLint attachment0Name = 0; +//* m_gl->functions()->glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, +//* GL_COLOR_ATTACHMENT0, +//* GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, +//* &attachmentObjectType); +//* m_gl->functions()->glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, +//* GL_COLOR_ATTACHMENT0, +//* GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, +//* &attachment0Name); +//* +//* if (attachmentObjectType == GL_RENDERBUFFER && m_glHelper->supportsFeature(GraphicsHelperInterface::RenderBufferDimensionRetrieval)) +//* renderTargetSize = m_glHelper->getRenderBufferDimensions(attachment0Name); +//* else if (attachmentObjectType == GL_TEXTURE && m_glHelper->supportsFeature(GraphicsHelperInterface::TextureDimensionRetrieval)) +//* // Assumes texture level 0 and GL_TEXTURE_2D target +//* renderTargetSize = m_glHelper->getTextureDimensions(attachment0Name, GL_TEXTURE_2D); +//* else +//* return renderTargetSize; +//* } +//* } else { +//* renderTargetSize = m_surface->size(); +//* if (m_surface->surfaceClass() == QSurface::Window) { +//* const float dpr = static_cast<QWindow *>(m_surface)->devicePixelRatio(); +//* renderTargetSize *= dpr; +//* } +//* } +//* return renderTargetSize; } QImage SubmissionContext::readFramebuffer(const QRect &rect) { - QImage img; - const unsigned int area = rect.width() * rect.height(); - unsigned int bytes; - GLenum format, type; - QImage::Format imageFormat; - uint stride; - - /* format value should match GL internalFormat */ - GLenum internalFormat = m_renderTargetFormat; - - switch (m_renderTargetFormat) { - case QAbstractTexture::RGBAFormat: - case QAbstractTexture::RGBA8_SNorm: - case QAbstractTexture::RGBA8_UNorm: - case QAbstractTexture::RGBA8U: - case QAbstractTexture::SRGB8_Alpha8: -#ifdef QT_OPENGL_ES_2 - format = GL_RGBA; - imageFormat = QImage::Format_RGBA8888_Premultiplied; -#else - format = GL_BGRA; - imageFormat = QImage::Format_ARGB32_Premultiplied; - internalFormat = GL_RGBA8; -#endif - type = GL_UNSIGNED_BYTE; - bytes = area * 4; - stride = rect.width() * 4; - break; - case QAbstractTexture::SRGB8: - case QAbstractTexture::RGBFormat: - case QAbstractTexture::RGB8U: - case QAbstractTexture::RGB8_UNorm: -#ifdef QT_OPENGL_ES_2 - format = GL_RGBA; - imageFormat = QImage::Format_RGBX8888; -#else - format = GL_BGRA; - imageFormat = QImage::Format_RGB32; - internalFormat = GL_RGB8; -#endif - type = GL_UNSIGNED_BYTE; - bytes = area * 4; - stride = rect.width() * 4; - break; -#ifndef QT_OPENGL_ES_2 - case QAbstractTexture::RG11B10F: - bytes = area * 4; - format = GL_RGB; - type = GL_UNSIGNED_INT_10F_11F_11F_REV; - imageFormat = QImage::Format_RGB30; - stride = rect.width() * 4; - break; - case QAbstractTexture::RGB10A2: - bytes = area * 4; - format = GL_RGBA; - type = GL_UNSIGNED_INT_2_10_10_10_REV; - imageFormat = QImage::Format_A2BGR30_Premultiplied; - stride = rect.width() * 4; - break; - case QAbstractTexture::R5G6B5: - bytes = area * 2; - format = GL_RGB; - type = GL_UNSIGNED_SHORT; - internalFormat = GL_UNSIGNED_SHORT_5_6_5_REV; - imageFormat = QImage::Format_RGB16; - stride = rect.width() * 2; - break; - case QAbstractTexture::RGBA16F: - case QAbstractTexture::RGBA16U: - case QAbstractTexture::RGBA32F: - case QAbstractTexture::RGBA32U: - bytes = area * 16; - format = GL_RGBA; - type = GL_FLOAT; - imageFormat = QImage::Format_ARGB32_Premultiplied; - stride = rect.width() * 16; - break; -#endif - default: - auto warning = qWarning(); - warning << "Unable to convert"; - QtDebugUtils::formatQEnum(warning, m_renderTargetFormat); - warning << "render target texture format to QImage."; - return img; - } - - GLint samples = 0; - m_gl->functions()->glGetIntegerv(GL_SAMPLES, &samples); - if (samples > 0 && !m_glHelper->supportsFeature(GraphicsHelperInterface::BlitFramebuffer)) { - qCWarning(Backend) << Q_FUNC_INFO << "Unable to capture multisampled framebuffer; " - "Required feature BlitFramebuffer is missing."; - return img; - } - - img = QImage(rect.width(), rect.height(), imageFormat); - - QScopedArrayPointer<uchar> data(new uchar [bytes]); - - if (samples > 0) { - // resolve multisample-framebuffer to renderbuffer and read pixels from it - GLuint fbo, rb; - QOpenGLFunctions *gl = m_gl->functions(); - gl->glGenFramebuffers(1, &fbo); - gl->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); - gl->glGenRenderbuffers(1, &rb); - gl->glBindRenderbuffer(GL_RENDERBUFFER, rb); - gl->glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, rect.width(), rect.height()); - gl->glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb); - - const GLenum status = gl->glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) { - gl->glDeleteRenderbuffers(1, &rb); - gl->glDeleteFramebuffers(1, &fbo); - qCWarning(Backend) << Q_FUNC_INFO << "Copy-framebuffer not complete: " << status; - return img; - } - - m_glHelper->blitFramebuffer(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height(), - 0, 0, rect.width(), rect.height(), - GL_COLOR_BUFFER_BIT, GL_NEAREST); - gl->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); - gl->glReadPixels(0,0,rect.width(), rect.height(), format, type, data.data()); - - copyGLFramebufferDataToImage(img, data.data(), stride, rect.width(), rect.height(), m_renderTargetFormat); - - gl->glBindRenderbuffer(GL_RENDERBUFFER, rb); - gl->glDeleteRenderbuffers(1, &rb); - gl->glBindFramebuffer(GL_FRAMEBUFFER, m_activeFBO); - gl->glDeleteFramebuffers(1, &fbo); - } else { - // read pixels directly from framebuffer - m_gl->functions()->glReadPixels(rect.x(), rect.y(), rect.width(), rect.height(), format, type, data.data()); - copyGLFramebufferDataToImage(img, data.data(), stride, rect.width(), rect.height(), m_renderTargetFormat); - } - - return img; + RHI_UNIMPLEMENTED; + return {}; +//* QImage img; +//* const unsigned int area = rect.width() * rect.height(); +//* unsigned int bytes; +//* GLenum format, type; +//* QImage::Format imageFormat; +//* uint stride; +//* +//* /* format value should match GL internalFormat */ +//* GLenum internalFormat = m_renderTargetFormat; +//* +//* switch (m_renderTargetFormat) { +//* case QAbstractTexture::RGBAFormat: +//* case QAbstractTexture::RGBA8_SNorm: +//* case QAbstractTexture::RGBA8_UNorm: +//* case QAbstractTexture::RGBA8U: +//* case QAbstractTexture::SRGB8_Alpha8: +//*#ifdef QT_OPENGL_ES_2 +//* format = GL_RGBA; +//* imageFormat = QImage::Format_RGBA8888_Premultiplied; +//*#else +//* format = GL_BGRA; +//* imageFormat = QImage::Format_ARGB32_Premultiplied; +//* internalFormat = GL_RGBA8; +//*#endif +//* type = GL_UNSIGNED_BYTE; +//* bytes = area * 4; +//* stride = rect.width() * 4; +//* break; +//* case QAbstractTexture::SRGB8: +//* case QAbstractTexture::RGBFormat: +//* case QAbstractTexture::RGB8U: +//* case QAbstractTexture::RGB8_UNorm: +//*#ifdef QT_OPENGL_ES_2 +//* format = GL_RGBA; +//* imageFormat = QImage::Format_RGBX8888; +//*#else +//* format = GL_BGRA; +//* imageFormat = QImage::Format_RGB32; +//* internalFormat = GL_RGB8; +//*#endif +//* type = GL_UNSIGNED_BYTE; +//* bytes = area * 4; +//* stride = rect.width() * 4; +//* break; +//*#ifndef QT_OPENGL_ES_2 +//* case QAbstractTexture::RG11B10F: +//* bytes = area * 4; +//* format = GL_RGB; +//* type = GL_UNSIGNED_INT_10F_11F_11F_REV; +//* imageFormat = QImage::Format_RGB30; +//* stride = rect.width() * 4; +//* break; +//* case QAbstractTexture::RGB10A2: +//* bytes = area * 4; +//* format = GL_RGBA; +//* type = GL_UNSIGNED_INT_2_10_10_10_REV; +//* imageFormat = QImage::Format_A2BGR30_Premultiplied; +//* stride = rect.width() * 4; +//* break; +//* case QAbstractTexture::R5G6B5: +//* bytes = area * 2; +//* format = GL_RGB; +//* type = GL_UNSIGNED_SHORT; +//* internalFormat = GL_UNSIGNED_SHORT_5_6_5_REV; +//* imageFormat = QImage::Format_RGB16; +//* stride = rect.width() * 2; +//* break; +//* case QAbstractTexture::RGBA16F: +//* case QAbstractTexture::RGBA16U: +//* case QAbstractTexture::RGBA32F: +//* case QAbstractTexture::RGBA32U: +//* bytes = area * 16; +//* format = GL_RGBA; +//* type = GL_FLOAT; +//* imageFormat = QImage::Format_ARGB32_Premultiplied; +//* stride = rect.width() * 16; +//* break; +//*#endif +//* default: +//* auto warning = qWarning(); +//* warning << "Unable to convert"; +//* QtDebugUtils::formatQEnum(warning, m_renderTargetFormat); +//* warning << "render target texture format to QImage."; +//* return img; +//* } +//* +//* GLint samples = 0; +//* m_gl->functions()->glGetIntegerv(GL_SAMPLES, &samples); +//* if (samples > 0 && !m_glHelper->supportsFeature(GraphicsHelperInterface::BlitFramebuffer)) { +//* qCWarning(Backend) << Q_FUNC_INFO << "Unable to capture multisampled framebuffer; " +//* "Required feature BlitFramebuffer is missing."; +//* return img; +//* } +//* +//* img = QImage(rect.width(), rect.height(), imageFormat); +//* +//* QScopedArrayPointer<uchar> data(new uchar [bytes]); +//* +//* if (samples > 0) { +//* // resolve multisample-framebuffer to renderbuffer and read pixels from it +//* GLuint fbo, rb; +//* QOpenGLFunctions *gl = m_gl->functions(); +//* gl->glGenFramebuffers(1, &fbo); +//* gl->glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); +//* gl->glGenRenderbuffers(1, &rb); +//* gl->glBindRenderbuffer(GL_RENDERBUFFER, rb); +//* gl->glRenderbufferStorage(GL_RENDERBUFFER, internalFormat, rect.width(), rect.height()); +//* gl->glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb); +//* +//* const GLenum status = gl->glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER); +//* if (status != GL_FRAMEBUFFER_COMPLETE) { +//* gl->glDeleteRenderbuffers(1, &rb); +//* gl->glDeleteFramebuffers(1, &fbo); +//* qCWarning(Backend) << Q_FUNC_INFO << "Copy-framebuffer not complete: " << status; +//* return img; +//* } +//* +//* m_glHelper->blitFramebuffer(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height(), +//* 0, 0, rect.width(), rect.height(), +//* GL_COLOR_BUFFER_BIT, GL_NEAREST); +//* gl->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo); +//* gl->glReadPixels(0,0,rect.width(), rect.height(), format, type, data.data()); +//* +//* copyGLFramebufferDataToImage(img, data.data(), stride, rect.width(), rect.height(), m_renderTargetFormat); +//* +//* gl->glBindRenderbuffer(GL_RENDERBUFFER, rb); +//* gl->glDeleteRenderbuffers(1, &rb); +//* gl->glBindFramebuffer(GL_FRAMEBUFFER, m_activeFBO); +//* gl->glDeleteFramebuffers(1, &fbo); +//* } else { +//* // read pixels directly from framebuffer +//* m_gl->functions()->glReadPixels(rect.x(), rect.y(), rect.width(), rect.height(), format, type, data.data()); +//* copyGLFramebufferDataToImage(img, data.data(), stride, rect.width(), rect.height(), m_renderTargetFormat); +//* } +//* +//* return img; } void SubmissionContext::setViewport(const QRectF &viewport, const QSize &surfaceSize) @@ -751,10 +771,12 @@ void SubmissionContext::setViewport(const QRectF &viewport, const QSize &surface // 1 0---------------------> 1 // The Viewport is defined between 0 and 1 which allows us to automatically // scale to the size of the provided window surface - m_gl->functions()->glViewport(m_viewport.x() * size.width(), - (1.0 - m_viewport.y() - m_viewport.height()) * size.height(), - m_viewport.width() * size.width(), - m_viewport.height() * size.height()); + + RHI_UNIMPLEMENTED; + //* m_gl->functions()->glViewport(m_viewport.x() * size.width(), + //* (1.0 - m_viewport.y() - m_viewport.height()) * size.height(), + //* m_viewport.width() * size.width(), + //* m_viewport.height() * size.height()); } void SubmissionContext::releaseOpenGL() @@ -771,83 +793,87 @@ void SubmissionContext::releaseOpenGL() // The OpenGLContext is not current on any surface at this point void SubmissionContext::setOpenGLContext(QOpenGLContext* ctx) { - Q_ASSERT(ctx); - - releaseOpenGL(); - m_gl = ctx; + RHI_UNIMPLEMENTED; + //* Q_ASSERT(ctx); + //* + //* releaseOpenGL(); + //* m_gl = ctx; } // Called only from RenderThread bool SubmissionContext::activateShader(RHIShader *shader) { - if (shader->shaderProgram() != m_activeShader) { - // Ensure material uniforms are re-applied - m_material = nullptr; - - m_activeShader = shader->shaderProgram(); - if (Q_LIKELY(m_activeShader != nullptr)) { - m_activeShader->bind(); - } else { - m_glHelper->useProgram(0); - qWarning() << "No shader program found"; - return false; - } - } + RHI_UNIMPLEMENTED; + //* if (shader->shaderProgram() != m_activeShader) { + //* // Ensure material uniforms are re-applied + //* m_material = nullptr; + //* + //* m_activeShader = shader->shaderProgram(); + //* if (Q_LIKELY(m_activeShader != nullptr)) { + //* m_activeShader->bind(); + //* } else { + //* m_glHelper->useProgram(0); + //* qWarning() << "No shader program found"; + //* return false; + //* } + //* } return true; } void SubmissionContext::bindFrameBufferAttachmentHelper(GLuint fboId, const AttachmentPack &attachments) { + RHI_UNIMPLEMENTED; // Set FBO attachments. These are normally textures, except that on Open GL // ES <= 3.1 we must use a renderbuffer if a combined depth+stencil is // desired since this cannot be achieved neither with a single texture (not // before GLES 3.2) nor with separate textures (no suitable format for // stencil before 3.1 with the appropriate extension). - QSize fboSize; - RHITextureManager *rhiTextureManager = m_renderer->rhiResourceManagers()->rhiTextureManager(); - const auto attachments_ = attachments.attachments(); - for (const Attachment &attachment : attachments_) { - RHITexture *rTex = rhiTextureManager->lookupResource(attachment.m_textureUuid); - if (!m_glHelper->frameBufferNeedsRenderBuffer(attachment)) { - QOpenGLTexture *glTex = rTex ? rTex->getGLTexture() : nullptr; - if (glTex != nullptr) { - // The texture can not be rendered simultaniously by another renderer - Q_ASSERT(!rTex->isExternalRenderingEnabled()); - if (fboSize.isEmpty()) - fboSize = QSize(glTex->width(), glTex->height()); - else - fboSize = QSize(qMin(fboSize.width(), glTex->width()), qMin(fboSize.height(), glTex->height())); - m_glHelper->bindFrameBufferAttachment(glTex, attachment); - } - } else { - RenderBuffer *renderBuffer = rTex ? rTex->getOrCreateRenderBuffer() : nullptr; - if (renderBuffer) { - if (fboSize.isEmpty()) - fboSize = QSize(renderBuffer->width(), renderBuffer->height()); - else - fboSize = QSize(qMin(fboSize.width(), renderBuffer->width()), qMin(fboSize.height(), renderBuffer->height())); - m_glHelper->bindFrameBufferAttachment(renderBuffer, attachment); - } - } - } - m_renderTargetsSize.insert(fboId, fboSize); + //* QSize fboSize; + //* RHITextureManager *rhiTextureManager = m_renderer->rhiResourceManagers()->rhiTextureManager(); + //* const auto attachments_ = attachments.attachments(); + //* for (const Attachment &attachment : attachments_) { + //* RHITexture *rTex = rhiTextureManager->lookupResource(attachment.m_textureUuid); + //* if (!m_glHelper->frameBufferNeedsRenderBuffer(attachment)) { + //* QOpenGLTexture *glTex = rTex ? rTex->getGLTexture() : nullptr; + //* if (glTex != nullptr) { + //* // The texture can not be rendered simultaniously by another renderer + //* Q_ASSERT(!rTex->isExternalRenderingEnabled()); + //* if (fboSize.isEmpty()) + //* fboSize = QSize(glTex->width(), glTex->height()); + //* else + //* fboSize = QSize(qMin(fboSize.width(), glTex->width()), qMin(fboSize.height(), glTex->height())); + //* m_glHelper->bindFrameBufferAttachment(glTex, attachment); + //* } + //* } else { + //* RenderBuffer *renderBuffer = rTex ? rTex->getOrCreateRenderBuffer() : nullptr; + //* if (renderBuffer) { + //* if (fboSize.isEmpty()) + //* fboSize = QSize(renderBuffer->width(), renderBuffer->height()); + //* else + //* fboSize = QSize(qMin(fboSize.width(), renderBuffer->width()), qMin(fboSize.height(), renderBuffer->height())); + //* m_glHelper->bindFrameBufferAttachment(renderBuffer, attachment); + //* } + //* } + //* } + //* m_renderTargetsSize.insert(fboId, fboSize); } void SubmissionContext::activateDrawBuffers(const AttachmentPack &attachments) { - const QVector<int> activeDrawBuffers = attachments.getGlDrawBuffers(); - - if (m_glHelper->checkFrameBufferComplete()) { - if (activeDrawBuffers.size() > 1) {// We need MRT - if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT)) { - // Set up MRT, glDrawBuffers... - m_glHelper->drawBuffers(activeDrawBuffers.size(), activeDrawBuffers.data()); - } - } - } else { - qCWarning(Backend) << "FBO incomplete"; - } + RHI_UNIMPLEMENTED; + //* const QVector<int> activeDrawBuffers = attachments.getGlDrawBuffers(); + //* + //* if (m_glHelper->checkFrameBufferComplete()) { + //* if (activeDrawBuffers.size() > 1) {// We need MRT + //* if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT)) { + //* // Set up MRT, glDrawBuffers... + //* m_glHelper->drawBuffers(activeDrawBuffers.size(), activeDrawBuffers.data()); + //* } + //* } + //* } else { + //* qCWarning(Backend) << "FBO incomplete"; + //* } } @@ -877,185 +903,188 @@ RenderStateSet *SubmissionContext::currentStateSet() const void SubmissionContext::applyState(const StateVariant &stateVariant) { - switch (stateVariant.type) { - - case AlphaCoverageStateMask: { - applyStateHelper<AlphaCoverage>(static_cast<const AlphaCoverage *>(stateVariant.constState()), this); - break; - } - case AlphaTestMask: { - applyStateHelper<AlphaFunc>(static_cast<const AlphaFunc *>(stateVariant.constState()), this); - break; - } - case BlendStateMask: { - applyStateHelper<BlendEquation>(static_cast<const BlendEquation *>(stateVariant.constState()), this); - break; - } - case BlendEquationArgumentsMask: { - applyStateHelper<BlendEquationArguments>(static_cast<const BlendEquationArguments *>(stateVariant.constState()), this); - break; - } - case MSAAEnabledStateMask: { - applyStateHelper<MSAAEnabled>(static_cast<const MSAAEnabled *>(stateVariant.constState()), this); - break; - } - - case CullFaceStateMask: { - applyStateHelper<CullFace>(static_cast<const CullFace *>(stateVariant.constState()), this); - break; - } - - case DepthWriteStateMask: { - applyStateHelper<NoDepthMask>(static_cast<const NoDepthMask *>(stateVariant.constState()), this); - break; - } - - case DepthTestStateMask: { - applyStateHelper<DepthTest>(static_cast<const DepthTest *>(stateVariant.constState()), this); - break; - } - - case DepthRangeMask: { - applyStateHelper<DepthRange>(static_cast<const DepthRange *>(stateVariant.constState()), this); - break; - } - - case RasterModeMask: { - applyStateHelper<RasterMode>(static_cast<const RasterMode *>(stateVariant.constState()), this); - break; - } - - case FrontFaceStateMask: { - applyStateHelper<FrontFace>(static_cast<const FrontFace *>(stateVariant.constState()), this); - break; - } - - case ScissorStateMask: { - applyStateHelper<ScissorTest>(static_cast<const ScissorTest *>(stateVariant.constState()), this); - break; - } - - case StencilTestStateMask: { - applyStateHelper<StencilTest>(static_cast<const StencilTest *>(stateVariant.constState()), this); - break; - } - - case PointSizeMask: { - applyStateHelper<PointSize>(static_cast<const PointSize *>(stateVariant.constState()), this); - break; - } - - case PolygonOffsetStateMask: { - applyStateHelper<PolygonOffset>(static_cast<const PolygonOffset *>(stateVariant.constState()), this); - break; - } - - case ColorStateMask: { - applyStateHelper<ColorMask>(static_cast<const ColorMask *>(stateVariant.constState()), this); - break; - } - - case ClipPlaneMask: { - applyStateHelper<ClipPlane>(static_cast<const ClipPlane *>(stateVariant.constState()), this); - break; - } - - case SeamlessCubemapMask: { - applyStateHelper<SeamlessCubemap>(static_cast<const SeamlessCubemap *>(stateVariant.constState()), this); - break; - } - - case StencilOpMask: { - applyStateHelper<StencilOp>(static_cast<const StencilOp *>(stateVariant.constState()), this); - break; - } - - case StencilWriteStateMask: { - applyStateHelper<StencilMask>(static_cast<const StencilMask *>(stateVariant.constState()), this); - break; - } - - case DitheringStateMask: { - applyStateHelper<Dithering>(static_cast<const Dithering *>(stateVariant.constState()), this); - break; - } - - case LineWidthMask: { - applyStateHelper<LineWidth>(static_cast<const LineWidth *>(stateVariant.constState()), this); - break; - } - default: - Q_UNREACHABLE(); - } + RHI_UNIMPLEMENTED; + +//* switch (stateVariant.type) { +//* +//* case AlphaCoverageStateMask: { +//* applyStateHelper<AlphaCoverage>(static_cast<const AlphaCoverage *>(stateVariant.constState()), this); +//* break; +//* } +//* case AlphaTestMask: { +//* applyStateHelper<AlphaFunc>(static_cast<const AlphaFunc *>(stateVariant.constState()), this); +//* break; +//* } +//* case BlendStateMask: { +//* applyStateHelper<BlendEquation>(static_cast<const BlendEquation *>(stateVariant.constState()), this); +//* break; +//* } +//* case BlendEquationArgumentsMask: { +//* applyStateHelper<BlendEquationArguments>(static_cast<const BlendEquationArguments *>(stateVariant.constState()), this); +//* break; +//* } +//* case MSAAEnabledStateMask: { +//* applyStateHelper<MSAAEnabled>(static_cast<const MSAAEnabled *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case CullFaceStateMask: { +//* applyStateHelper<CullFace>(static_cast<const CullFace *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case DepthWriteStateMask: { +//* applyStateHelper<NoDepthMask>(static_cast<const NoDepthMask *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case DepthTestStateMask: { +//* applyStateHelper<DepthTest>(static_cast<const DepthTest *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case DepthRangeMask: { +//* applyStateHelper<DepthRange>(static_cast<const DepthRange *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case RasterModeMask: { +//* applyStateHelper<RasterMode>(static_cast<const RasterMode *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case FrontFaceStateMask: { +//* applyStateHelper<FrontFace>(static_cast<const FrontFace *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case ScissorStateMask: { +//* applyStateHelper<ScissorTest>(static_cast<const ScissorTest *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case StencilTestStateMask: { +//* applyStateHelper<StencilTest>(static_cast<const StencilTest *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case PointSizeMask: { +//* applyStateHelper<PointSize>(static_cast<const PointSize *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case PolygonOffsetStateMask: { +//* applyStateHelper<PolygonOffset>(static_cast<const PolygonOffset *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case ColorStateMask: { +//* applyStateHelper<ColorMask>(static_cast<const ColorMask *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case ClipPlaneMask: { +//* applyStateHelper<ClipPlane>(static_cast<const ClipPlane *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case SeamlessCubemapMask: { +//* applyStateHelper<SeamlessCubemap>(static_cast<const SeamlessCubemap *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case StencilOpMask: { +//* applyStateHelper<StencilOp>(static_cast<const StencilOp *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case StencilWriteStateMask: { +//* applyStateHelper<StencilMask>(static_cast<const StencilMask *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case DitheringStateMask: { +//* applyStateHelper<Dithering>(static_cast<const Dithering *>(stateVariant.constState()), this); +//* break; +//* } +//* +//* case LineWidthMask: { +//* applyStateHelper<LineWidth>(static_cast<const LineWidth *>(stateVariant.constState()), this); +//* break; +//* } +//* default: +//* Q_UNREACHABLE(); +//* } } void SubmissionContext::resetMasked(qint64 maskOfStatesToReset) { - // TO DO -> Call gcHelper methods instead of raw GL - // QOpenGLFunctions shouldn't be used here directly - QOpenGLFunctions *funcs = m_gl->functions(); - - if (maskOfStatesToReset & ScissorStateMask) - funcs->glDisable(GL_SCISSOR_TEST); - - if (maskOfStatesToReset & BlendStateMask) - funcs->glDisable(GL_BLEND); - - if (maskOfStatesToReset & StencilWriteStateMask) - funcs->glStencilMask(0); - - if (maskOfStatesToReset & StencilTestStateMask) - funcs->glDisable(GL_STENCIL_TEST); - - if (maskOfStatesToReset & DepthRangeMask) - depthRange(0.0f, 1.0f); - - if (maskOfStatesToReset & DepthTestStateMask) - funcs->glDisable(GL_DEPTH_TEST); - - if (maskOfStatesToReset & DepthWriteStateMask) - funcs->glDepthMask(GL_TRUE); // reset to default - - if (maskOfStatesToReset & FrontFaceStateMask) - funcs->glFrontFace(GL_CCW); // reset to default - - if (maskOfStatesToReset & CullFaceStateMask) - funcs->glDisable(GL_CULL_FACE); - - if (maskOfStatesToReset & DitheringStateMask) - funcs->glDisable(GL_DITHER); - - if (maskOfStatesToReset & AlphaCoverageStateMask) - setAlphaCoverageEnabled(false); - - if (maskOfStatesToReset & PointSizeMask) - pointSize(false, 1.0f); // reset to default - - if (maskOfStatesToReset & PolygonOffsetStateMask) - funcs->glDisable(GL_POLYGON_OFFSET_FILL); - - if (maskOfStatesToReset & ColorStateMask) - funcs->glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - - if (maskOfStatesToReset & ClipPlaneMask) { - GLint max = maxClipPlaneCount(); - for (GLint i = 0; i < max; ++i) - disableClipPlane(i); - } - - if (maskOfStatesToReset & SeamlessCubemapMask) - setSeamlessCubemap(false); - - if (maskOfStatesToReset & StencilOpMask) - funcs->glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - - if (maskOfStatesToReset & LineWidthMask) - funcs->glLineWidth(1.0f); - -#ifndef QT_OPENGL_ES_2 - if (maskOfStatesToReset & RasterModeMask) - m_glHelper->rasterMode(GL_FRONT_AND_BACK, GL_FILL); -#endif + RHI_UNIMPLEMENTED; +//* // TO DO -> Call gcHelper methods instead of raw GL +//* // QOpenGLFunctions shouldn't be used here directly +//* QOpenGLFunctions *funcs = m_gl->functions(); +//* +//* if (maskOfStatesToReset & ScissorStateMask) +//* funcs->glDisable(GL_SCISSOR_TEST); +//* +//* if (maskOfStatesToReset & BlendStateMask) +//* funcs->glDisable(GL_BLEND); +//* +//* if (maskOfStatesToReset & StencilWriteStateMask) +//* funcs->glStencilMask(0); +//* +//* if (maskOfStatesToReset & StencilTestStateMask) +//* funcs->glDisable(GL_STENCIL_TEST); +//* +//* if (maskOfStatesToReset & DepthRangeMask) +//* depthRange(0.0f, 1.0f); +//* +//* if (maskOfStatesToReset & DepthTestStateMask) +//* funcs->glDisable(GL_DEPTH_TEST); +//* +//* if (maskOfStatesToReset & DepthWriteStateMask) +//* funcs->glDepthMask(GL_TRUE); // reset to default +//* +//* if (maskOfStatesToReset & FrontFaceStateMask) +//* funcs->glFrontFace(GL_CCW); // reset to default +//* +//* if (maskOfStatesToReset & CullFaceStateMask) +//* funcs->glDisable(GL_CULL_FACE); +//* +//* if (maskOfStatesToReset & DitheringStateMask) +//* funcs->glDisable(GL_DITHER); +//* +//* if (maskOfStatesToReset & AlphaCoverageStateMask) +//* setAlphaCoverageEnabled(false); +//* +//* if (maskOfStatesToReset & PointSizeMask) +//* pointSize(false, 1.0f); // reset to default +//* +//* if (maskOfStatesToReset & PolygonOffsetStateMask) +//* funcs->glDisable(GL_POLYGON_OFFSET_FILL); +//* +//* if (maskOfStatesToReset & ColorStateMask) +//* funcs->glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); +//* +//* if (maskOfStatesToReset & ClipPlaneMask) { +//* GLint max = maxClipPlaneCount(); +//* for (GLint i = 0; i < max; ++i) +//* disableClipPlane(i); +//* } +//* +//* if (maskOfStatesToReset & SeamlessCubemapMask) +//* setSeamlessCubemap(false); +//* +//* if (maskOfStatesToReset & StencilOpMask) +//* funcs->glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +//* +//* if (maskOfStatesToReset & LineWidthMask) +//* funcs->glLineWidth(1.0f); +//* +//* #ifndef QT_OPENGL_ES_2 +//* if (maskOfStatesToReset & RasterModeMask) +//* m_glHelper->rasterMode(GL_FRONT_AND_BACK, GL_FILL); +//* #endif } void SubmissionContext::applyStateSet(RenderStateSet *ss) @@ -1088,53 +1117,63 @@ void SubmissionContext::applyStateSet(RenderStateSet *ss) void SubmissionContext::clearColor(const QColor &color) { - if (m_currClearColorValue != color) { - m_currClearColorValue = color; - m_gl->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); - } + RHI_UNIMPLEMENTED; +//* if (m_currClearColorValue != color) { +//* m_currClearColorValue = color; +//* m_gl->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); +//* } } void SubmissionContext::clearDepthValue(float depth) { - if (m_currClearDepthValue != depth) { - m_currClearDepthValue = depth; - m_gl->functions()->glClearDepthf(depth); - } + RHI_UNIMPLEMENTED; +//* if (m_currClearDepthValue != depth) { +//* m_currClearDepthValue = depth; +//* m_gl->functions()->glClearDepthf(depth); +//* } } void SubmissionContext::clearStencilValue(int stencil) { - if (m_currClearStencilValue != stencil) { - m_currClearStencilValue = stencil; - m_gl->functions()->glClearStencil(stencil); - } + RHI_UNIMPLEMENTED; +//* if (m_currClearStencilValue != stencil) { +//* m_currClearStencilValue = stencil; +//* m_gl->functions()->glClearStencil(stencil); +//* } } RHIFence SubmissionContext::fenceSync() { - return m_glHelper->fenceSync(); + RHI_UNIMPLEMENTED; + return {}; +//* return m_glHelper->fenceSync(); } void SubmissionContext::clientWaitSync(RHIFence sync, GLuint64 nanoSecTimeout) { - qDebug() << Q_FUNC_INFO << sync; - m_glHelper->clientWaitSync(sync, nanoSecTimeout); + RHI_UNIMPLEMENTED; +//* qDebug() << Q_FUNC_INFO << sync; +//* m_glHelper->clientWaitSync(sync, nanoSecTimeout); } void SubmissionContext::waitSync(RHIFence sync) { - qDebug() << Q_FUNC_INFO << sync; - m_glHelper->waitSync(sync); + RHI_UNIMPLEMENTED; +//* qDebug() << Q_FUNC_INFO << sync; +//* m_glHelper->waitSync(sync); } bool SubmissionContext::wasSyncSignaled(RHIFence sync) { - return m_glHelper->wasSyncSignaled(sync); + RHI_UNIMPLEMENTED; + return true; +//* return m_glHelper->wasSyncSignaled(sync); } void SubmissionContext::deleteSync(RHIFence sync) { - m_glHelper->deleteSync(sync); + RHI_UNIMPLEMENTED; +//* m_glHelper->deleteSync(sync); } // It will be easier if the QGraphicContext applies the QUniformPack @@ -1155,31 +1194,33 @@ bool SubmissionContext::setParameters(ShaderParameterPack ¶meterPack) // Fill Texture Uniform Value with proper texture units // so that they can be applied as regular uniforms in a second step for (int i = 0; i < parameterPack.textures().size(); ++i) { - const ShaderParameterPack::NamedResource &namedTex = parameterPack.textures().at(i); - // Given a Texture QNodeId, we retrieve the associated shared RHITexture - if (uniformValues.contains(namedTex.glslNameId)) { - RHITexture *t = m_renderer->rhiResourceManagers()->rhiTextureManager()->lookupResource(namedTex.nodeId); - if (t != nullptr) { - UniformValue &texUniform = uniformValues.value(namedTex.glslNameId); - if (texUniform.valueType() == UniformValue::TextureValue) { - const int texUnit = m_textureContext.activateTexture(TextureSubmissionContext::TextureScopeMaterial, m_gl, t); - texUniform.data<int>()[namedTex.uniformArrayIndex] = texUnit; - if (texUnit == -1) { - if (namedTex.glslNameId != irradianceId && - namedTex.glslNameId != specularId) { - // Only return false if we are not dealing with env light textures - qCWarning(Backend) << "Unable to find suitable Texture Unit"; - return false; - } - } - } - } - } + RHI_UNIMPLEMENTED; + //* const ShaderParameterPack::NamedResource &namedTex = parameterPack.textures().at(i); + //* // Given a Texture QNodeId, we retrieve the associated shared RHITexture + //* if (uniformValues.contains(namedTex.glslNameId)) { + //* RHITexture *t = m_renderer->rhiResourceManagers()->rhiTextureManager()->lookupResource(namedTex.nodeId); + //* if (t != nullptr) { + //* UniformValue &texUniform = uniformValues.value(namedTex.glslNameId); + //* if (texUniform.valueType() == UniformValue::TextureValue) { + //* const int texUnit = m_textureContext.activateTexture(TextureSubmissionContext::TextureScopeMaterial, m_gl, t); + //* texUniform.data<int>()[namedTex.uniformArrayIndex] = texUnit; + //* if (texUnit == -1) { + //* if (namedTex.glslNameId != irradianceId && + //* namedTex.glslNameId != specularId) { + //* // Only return false if we are not dealing with env light textures + //* qCWarning(Backend) << "Unable to find suitable Texture Unit"; + //* return false; + //* } + //* } + //* } + //* } + //* } } // Fill Image Uniform Value with proper image units // so that they can be applied as regular uniforms in a second step for (int i = 0; i < parameterPack.images().size(); ++i) { + RHI_UNIMPLEMENTED; const ShaderParameterPack::NamedResource &namedTex = parameterPack.images().at(i); // Given a Texture QNodeId, we retrieve the associated shared RHITexture if (uniformValues.contains(namedTex.glslNameId)) { @@ -1212,6 +1253,7 @@ bool SubmissionContext::setParameters(ShaderParameterPack ¶meterPack) // Bind Shader Storage block to SSBO and update SSBO const QVector<BlockToSSBO> blockToSSBOs = parameterPack.shaderStorageBuffers(); for (const BlockToSSBO b : blockToSSBOs) { + RHI_UNIMPLEMENTED; Buffer *cpuBuffer = m_renderer->nodeManagers()->bufferManager()->lookupResource(b.m_bufferID); RHIBuffer *ssbo = glBufferForRenderBuffer(cpuBuffer); // bindShaderStorageBlock @@ -1231,6 +1273,7 @@ bool SubmissionContext::setParameters(ShaderParameterPack ¶meterPack) const QVector<BlockToUBO> blockToUBOs = parameterPack.uniformBuffers(); int uboIndex = 0; for (const BlockToUBO &b : blockToUBOs) { + RHI_UNIMPLEMENTED; Buffer *cpuBuffer = m_renderer->nodeManagers()->bufferManager()->lookupResource(b.m_bufferID); RHIBuffer *ubo = glBufferForRenderBuffer(cpuBuffer); bindUniformBlock(shader->programId(), b.m_blockIndex, uboIndex); @@ -1264,26 +1307,29 @@ bool SubmissionContext::setParameters(ShaderParameterPack ¶meterPack) void SubmissionContext::enableAttribute(const VAOVertexAttribute &attr) { - // Bind buffer within the current VAO - RHIBuffer *buf = m_renderer->rhiResourceManagers()->rhiBufferManager()->data(attr.bufferHandle); - Q_ASSERT(buf); - bindGLBuffer(buf, attr.attributeType); - - // Don't use QOpenGLShaderProgram::setAttributeBuffer() because of QTBUG-43199. - // Use the introspection data and set the attribute explicitly - m_glHelper->enableVertexAttributeArray(attr.location); - m_glHelper->vertexAttributePointer(attr.shaderDataType, - attr.location, - attr.vertexSize, - attr.dataType, - GL_TRUE, // TODO: Support normalization property on QAttribute - attr.byteStride, - reinterpret_cast<const void *>(qintptr(attr.byteOffset))); - - - // Done by the helper if it supports it - if (attr.divisor != 0) - m_glHelper->vertexAttribDivisor(attr.location, attr.divisor); + RHI_UNIMPLEMENTED; +//* // Bind buffer within the current VAO +//* RHIBuffer *buf = m_renderer->rhiResourceManagers()->rhiBufferManager()->data(attr.bufferHandle); +//* Q_ASSERT(buf); +//* bindGLBuffer(buf, attr.attributeType); +//* +//* // Don't use QOpenGLShaderProgram::setAttributeBuffer() because of QTBUG-43199. +//* // Use the introspection data and set the attribute explicitly +//* m_glHelper->enableVertexAttributeArray(attr.location); +//* m_glHelper->vertexAttributePointer(attr.shaderDataType, +//* attr.location, +//* attr.vertexSize, +//* attr.dataType, +//* GL_TRUE, // TODO: Support normalization property on QAttribute +//* attr.byteStride, +//* reinterpret_cast<const void *>(qintptr(attr.byteOffset))); +//* +//* +//* // Done by the helper if it supports it +//* if (attr.divisor != 0) +//* { +//* m_glHelper->vertexAttribDivisor(attr.location, attr.divisor); +//* } } void SubmissionContext::disableAttribute(const SubmissionContext::VAOVertexAttribute &attr) @@ -1404,32 +1450,19 @@ RHIBuffer *SubmissionContext::glBufferForRenderBuffer(Buffer *buf) HRHIBuffer SubmissionContext::createGLBufferFor(Buffer *buffer) { - RHIBuffer *b = m_renderer->rhiResourceManagers()->rhiBufferManager()->getOrCreateResource(buffer->peerId()); - // b.setUsagePattern(static_cast<QOpenGLBuffer::UsagePattern>(buffer->usage())); - Q_ASSERT(b); - if (!b->create(this)) - qCWarning(Io) << Q_FUNC_INFO << "buffer creation failed"; - + m_renderer->rhiResourceManagers()->rhiBufferManager()->getOrCreateResource(buffer->peerId()); return m_renderer->rhiResourceManagers()->rhiBufferManager()->lookupHandle(buffer->peerId()); } bool SubmissionContext::bindGLBuffer(RHIBuffer *buffer, RHIBuffer::Type type) { - if (type == RHIBuffer::ArrayBuffer && buffer == m_boundArrayBuffer) - return true; - - if (buffer->bind(this, type)) { - if (type == RHIBuffer::ArrayBuffer) - m_boundArrayBuffer = buffer; - return true; - } - return false; + return buffer->bind(this, type); } void SubmissionContext::uploadDataToGLBuffer(Buffer *buffer, RHIBuffer *b, bool releaseBuffer) { - if (!bindGLBuffer(b, RHIBuffer::ArrayBuffer)) // We're uploading, the type doesn't matter here - qCWarning(Io) << Q_FUNC_INFO << "buffer bind failed"; + // if (!bindGLBuffer(b, RHIBuffer::ArrayBuffer)) // We're uploading, the type doesn't matter here + // qCWarning(Io) << Q_FUNC_INFO << "buffer bind failed"; // If the buffer is dirty (hence being called here) // there are two possible cases // * setData was called changing the whole data or functor (or the usage pattern) @@ -1457,20 +1490,18 @@ void SubmissionContext::uploadDataToGLBuffer(Buffer *buffer, RHIBuffer *b, bool } // TO DO: based on the number of updates .., it might make sense to // sometime use glMapBuffer rather than glBufferSubData - b->update(this, update->data.constData(), update->data.size(), update->offset); + b->update(this, update->data, update->offset); } else { // We have an update that was done by calling QBuffer::setData // which is used to resize or entirely clear the buffer // Note: we use the buffer data directly in that case - const int bufferSize = buffer->data().size(); - b->allocate(this, bufferSize, false); // orphan the buffer - b->allocate(this, buffer->data().constData(), bufferSize, false); + b->orphan(this); // orphan the buffer + b->allocate(this, buffer->data(), false); } } if (releaseBuffer) { b->release(this); - m_boundArrayBuffer = nullptr; } qCDebug(Io) << "uploaded buffer size=" << buffer->data().size(); } @@ -1492,81 +1523,82 @@ void SubmissionContext::blitFramebuffer(Qt3DCore::QNodeId inputRenderTargetId, QRenderTargetOutput::AttachmentPoint outputAttachmentPoint, QBlitFramebuffer::InterpolationMethod interpolationMethod) { - GLuint inputFboId = defaultFboId; - bool inputBufferIsDefault = true; - if (!inputRenderTargetId.isNull()) { - RenderTarget *renderTarget = m_renderer->nodeManagers()->renderTargetManager()->lookupResource(inputRenderTargetId); - if (renderTarget) { - AttachmentPack attachments(renderTarget, m_renderer->nodeManagers()->attachmentManager()); - if (m_renderTargets.contains(inputRenderTargetId)) - inputFboId = updateRenderTarget(inputRenderTargetId, attachments, false); - else - inputFboId = createRenderTarget(inputRenderTargetId, attachments); - } - inputBufferIsDefault = false; - } - - GLuint outputFboId = defaultFboId; - bool outputBufferIsDefault = true; - if (!outputRenderTargetId.isNull()) { - RenderTarget *renderTarget = m_renderer->nodeManagers()->renderTargetManager()->lookupResource(outputRenderTargetId); - if (renderTarget) { - AttachmentPack attachments(renderTarget, m_renderer->nodeManagers()->attachmentManager()); - if (m_renderTargets.contains(outputRenderTargetId)) - outputFboId = updateRenderTarget(outputRenderTargetId, attachments, false); - else - outputFboId = createRenderTarget(outputRenderTargetId, attachments); - } - outputBufferIsDefault = false; - } - - // Up until this point the input and output rects are normal Qt rectangles. - // Convert them to GL rectangles (Y at bottom). - const int inputFboHeight = inputFboId == defaultFboId ? m_surfaceSize.height() : m_renderTargetsSize[inputFboId].height(); - const GLint srcX0 = inputRect.left(); - const GLint srcY0 = inputFboHeight - (inputRect.top() + inputRect.height()); - const GLint srcX1 = srcX0 + inputRect.width(); - const GLint srcY1 = srcY0 + inputRect.height(); - - const int outputFboHeight = outputFboId == defaultFboId ? m_surfaceSize.height() : m_renderTargetsSize[outputFboId].height(); - const GLint dstX0 = outputRect.left(); - const GLint dstY0 = outputFboHeight - (outputRect.top() + outputRect.height()); - const GLint dstX1 = dstX0 + outputRect.width(); - const GLint dstY1 = dstY0 + outputRect.height(); - - //Get the last bounded framebuffers - const GLuint lastDrawFboId = boundFrameBufferObject(); - - // Activate input framebuffer for reading - bindFramebuffer(inputFboId, GraphicsHelperInterface::FBORead); - - // Activate output framebuffer for writing - bindFramebuffer(outputFboId, GraphicsHelperInterface::FBODraw); - - //Bind texture - if (!inputBufferIsDefault) - readBuffer(GL_COLOR_ATTACHMENT0 + inputAttachmentPoint); - - if (!outputBufferIsDefault) { - // Note that we use glDrawBuffers, not glDrawBuffer. The - // latter is not available with GLES. - const int buf = outputAttachmentPoint; - drawBuffers(1, &buf); - } - - // Blit framebuffer - const GLenum mode = interpolationMethod ? GL_NEAREST : GL_LINEAR; - m_glHelper->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, - dstX0, dstY0, dstX1, dstY1, - GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT, - mode); - - // Reset draw buffer - bindFramebuffer(lastDrawFboId, GraphicsHelperInterface::FBOReadAndDraw); - if (outputAttachmentPoint != QRenderTargetOutput::Color0) { - const int buf = QRenderTargetOutput::Color0; - drawBuffers(1, &buf); - } + RHI_UNIMPLEMENTED; +//* GLuint inputFboId = defaultFboId; +//* bool inputBufferIsDefault = true; +//* if (!inputRenderTargetId.isNull()) { +//* RenderTarget *renderTarget = m_renderer->nodeManagers()->renderTargetManager()->lookupResource(inputRenderTargetId); +//* if (renderTarget) { +//* AttachmentPack attachments(renderTarget, m_renderer->nodeManagers()->attachmentManager()); +//* if (m_renderTargets.contains(inputRenderTargetId)) +//* inputFboId = updateRenderTarget(inputRenderTargetId, attachments, false); +//* else +//* inputFboId = createRenderTarget(inputRenderTargetId, attachments); +//* } +//* inputBufferIsDefault = false; +//* } +//* +//* GLuint outputFboId = defaultFboId; +//* bool outputBufferIsDefault = true; +//* if (!outputRenderTargetId.isNull()) { +//* RenderTarget *renderTarget = m_renderer->nodeManagers()->renderTargetManager()->lookupResource(outputRenderTargetId); +//* if (renderTarget) { +//* AttachmentPack attachments(renderTarget, m_renderer->nodeManagers()->attachmentManager()); +//* if (m_renderTargets.contains(outputRenderTargetId)) +//* outputFboId = updateRenderTarget(outputRenderTargetId, attachments, false); +//* else +//* outputFboId = createRenderTarget(outputRenderTargetId, attachments); +//* } +//* outputBufferIsDefault = false; +//* } +//* +//* // Up until this point the input and output rects are normal Qt rectangles. +//* // Convert them to GL rectangles (Y at bottom). +//* const int inputFboHeight = inputFboId == defaultFboId ? m_surfaceSize.height() : m_renderTargetsSize[inputFboId].height(); +//* const GLint srcX0 = inputRect.left(); +//* const GLint srcY0 = inputFboHeight - (inputRect.top() + inputRect.height()); +//* const GLint srcX1 = srcX0 + inputRect.width(); +//* const GLint srcY1 = srcY0 + inputRect.height(); +//* +//* const int outputFboHeight = outputFboId == defaultFboId ? m_surfaceSize.height() : m_renderTargetsSize[outputFboId].height(); +//* const GLint dstX0 = outputRect.left(); +//* const GLint dstY0 = outputFboHeight - (outputRect.top() + outputRect.height()); +//* const GLint dstX1 = dstX0 + outputRect.width(); +//* const GLint dstY1 = dstY0 + outputRect.height(); +//* +//* //Get the last bounded framebuffers +//* const GLuint lastDrawFboId = boundFrameBufferObject(); +//* +//* // Activate input framebuffer for reading +//* bindFramebuffer(inputFboId, GraphicsHelperInterface::FBORead); +//* +//* // Activate output framebuffer for writing +//* bindFramebuffer(outputFboId, GraphicsHelperInterface::FBODraw); +//* +//* //Bind texture +//* if (!inputBufferIsDefault) +//* readBuffer(GL_COLOR_ATTACHMENT0 + inputAttachmentPoint); +//* +//* if (!outputBufferIsDefault) { +//* // Note that we use glDrawBuffers, not glDrawBuffer. The +//* // latter is not available with GLES. +//* const int buf = outputAttachmentPoint; +//* drawBuffers(1, &buf); +//* } +//* +//* // Blit framebuffer +//* const GLenum mode = interpolationMethod ? GL_NEAREST : GL_LINEAR; +//* m_glHelper->blitFramebuffer(srcX0, srcY0, srcX1, srcY1, +//* dstX0, dstY0, dstX1, dstY1, +//* GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT, +//* mode); +//* +//* // Reset draw buffer +//* bindFramebuffer(lastDrawFboId, GraphicsHelperInterface::FBOReadAndDraw); +//* if (outputAttachmentPoint != QRenderTargetOutput::Color0) { +//* const int buf = QRenderTargetOutput::Color0; +//* drawBuffers(1, &buf); +//* } } } // namespace Rhi diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h index 602dc7e35..de64aed74 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h @@ -200,7 +200,6 @@ private: QRectF m_viewport; GLuint m_activeFBO; - RHIBuffer *m_boundArrayBuffer; RenderStateSet* m_stateSet; Renderer *m_renderer; QByteArray m_uboTempArray; |