I upgraded qt5.12.0 to qt6.5.2, and trying to get code compiled in the new version of qt.
In our code we use QSGSimpleMaterial and QSGSimpleMaterialShader, and qt openGL:
#include "arcnode.h"
#include <QtCore/QResource>
// QSGSimpleMaterial: No such file or directory
#include <QtQuick/QSGSimpleMaterial>
class ArcShader : public QSGSimpleMaterialShader<ArcMaterial>
{
// expected a declaration
QSG_DECLARE_SIMPLE_SHADER( ArcShader, ArcMaterial )
public:
const char *vertexShader() const
{
QResource r( ":/components/shaders/arc.vsh" );
Q_ASSERT( r.isValid() );
return reinterpret_cast<const char *>( r.data() );
}
const char *fragmentShader() const
{
QResource r( ":/components/shaders/arc.fsh" );
Q_ASSERT( r.isValid() );
return reinterpret_cast<const char *>( r.data() );
}
QList<QByteArray> attributes() const
{
return QList<QByteArray>() << "pos" << "t";
}
void updateState( const ArcMaterial *m, const ArcMaterial * )
{
// No opengl now
program()->setUniformValue( id_color, m->color );
program()->setUniformValue( id_size, m->size );
}
void resolveUniforms()
{
// No opengl now
id_size = program()->uniformLocation( "size" );
id_color = program()->uniformLocation( "color" );
}
private:
int id_color;
int id_size;
};
static const QSGGeometry::AttributeSet &attributes()
{
static QSGGeometry::Attribute attr[] =
{
// opengl
QSGGeometry::Attribute::create( 0, 2, GL_FLOAT, true ),
QSGGeometry::Attribute::create( 1, 1, GL_FLOAT, false )
};
static QSGGeometry::AttributeSet set = { 2, sizeof( ArcVertex ), attr };
return set;
}
ArcNode::ArcNode( float size, const QColor &color )
: m_geometry( attributes(), 200 * 2 + 2 )
{
setGeometry( &m_geometry );
// opengl
m_geometry.setDrawingMode( GL_TRIANGLE_STRIP );
QSGSimpleMaterial<ArcMaterial> *m = ArcShader::createMaterial();
m->state()->color = color;
m->state()->size = size;
m->setFlag( QSGMaterial::Blending );
setMaterial( m );
setFlag( OwnsMaterial );
}
The above code based on QSGSimpleMaterialShader, and use QopenGl, but all these get removed in qt6, how should I rewrite the above class?
Error message: Arcnode.cpp error
The code below relies on the above class, and also use QSGSimpleMaterial which removed in qt6:
QSGNode *CircularArc::updatePaintNode( QSGNode *oldNode, UpdatePaintNodeData * )
{
ArcNode *node = nullptr;
QSGGeometry *geometry = nullptr;
int segmentCount = 200;//abs((2*M_PI*m_outerRadius*(m_interval/360)));
if( !oldNode )
{
node = new ArcNode( static_cast<float>( m_arcBarWidth ), m_color );
geometry = node->geometry();
}
else
{
node = static_cast<ArcNode *>( oldNode );
// QSGSimpleMaterial does not name a type
static_cast< QSGSimpleMaterial<ArcMaterial>*>( ( node->material() ) )->state()->color = m_color;
geometry = node->geometry();
int static verticeCount = segmentCount * 2 + 2;
geometry->allocate( verticeCount );
}
QRectF bounds = boundingRect();
ArcVertex *vertices = static_cast<ArcVertex *>( geometry->vertexData() );
qreal radianFactor = ( M_PI/180 );
for( int i = 0; i <= segmentCount; ++i )
{
/* (x1, y1) */
float radiansX = static_cast<float>( ( m_startAngle + ( ( m_interval / segmentCount ) * i ) )
* radianFactor );
float radiansY = static_cast<float>( ( m_startAngle + ( ( m_interval / segmentCount ) * i ) )
* radianFactor );
float cosVal = cosf( radiansX );
float sinVal = sinf( radiansY );
float x1 = static_cast<float>( bounds.x()
+ ( ( m_outerRadius - m_arcBarWidth ) * static_cast<qreal>( cosVal ) )
+ bounds.width() / 2 );
float y1 = static_cast<float>( bounds.y()
- ( ( m_outerRadius - m_arcBarWidth ) * static_cast<qreal>( sinVal ) )
+ bounds.height() / 2 );
/* (x2, y2) */
float x2 = static_cast<float>( bounds.x()
+ ( m_outerRadius * static_cast<qreal>( cosVal ) )
+ bounds.width() / 2 );
float y2 = static_cast<float>( bounds.y()
- ( m_outerRadius * static_cast<qreal>( sinVal ) )
+ bounds.height() / 2 );
int indexOffset = i * 2;
vertices[indexOffset].set( x1, y1, 0 );
vertices[indexOffset + 1].set( x2, y2, 1 );
}
node->markDirty( QSGNode::DirtyGeometry );
return node;
}
Error message: arc.cpp error
And also this one:
void ScatterPlotRenderer::render()
{
glDepthMask(true);
glClearColor(static_cast<GLclampf>(m_backgroundColor.redF()),
static_cast<GLclampf>(m_backgroundColor.greenF()),
static_cast<GLclampf>(m_backgroundColor.blueF()),
static_cast<GLclampf>(m_backgroundColor.alphaF()));
glClear(GL_COLOR_BUFFER_BIT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
scatterplotShaderProgram.bind();
paintGrid();
paintPoints();
scatterplotShaderProgram.release();
//update();
// class QQuickWindow has no member named resetOpenGLState
m_window->resetOpenGLState();
}
Error message: no opengl
How to fix the errors.