Simply matrix calcs. Fix for clang

pull/1291/head
Jon Beniston 2022-06-18 13:07:10 +01:00
rodzic d441e6d475
commit c135affb6a
3 zmienionych plików z 35 dodań i 43 usunięć

Wyświetl plik

@ -310,7 +310,7 @@ void GLShaderSpectrogram::subTextureMutable(int xOffset, int yOffset, int width,
glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels);
}
void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style, float textureOffset, bool invert)
void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style, const QMatrix4x4& vertexTransform, float textureOffset, bool invert)
{
if ((m_useImmutableStorage && !m_texture) || (!m_useImmutableStorage && !m_textureId))
{
@ -325,17 +325,6 @@ void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style,
program = m_programSimple;
}
// Note that translation to the origin and rotation
// needs to be performed in reverse order to what you
// might normally expect
// See: https://bugreports.qt.io/browse/QTBUG-20752
QMatrix4x4 vertexTransform;
vertexTransform.translate(0.0f, 0.0f, -1.65f);
applyScaleRotate(vertexTransform);
vertexTransform.translate(-0.5f, -0.5f, 0.0f);
applyPerspective(vertexTransform);
float rot = invert ? 1.0 : -1.0;
QMatrix4x4 textureTransform(
1.0, 0.0, 0.0, 0.0,
@ -652,14 +641,20 @@ void GLShaderSpectrogram::lightRotateZ(float degrees)
m_lightRotZ += degrees;
}
void GLShaderSpectrogram::applyScaleRotate(QMatrix4x4 &matrix)
void GLShaderSpectrogram::applyTransform(QMatrix4x4 &matrix)
{
// As above, this is in reverse
matrix.translate(m_translateX, m_translateY, m_translateZ);
matrix.rotate(m_rotX, 1.0f, 0.0f, 0.0f);
// Note that translation to the origin and rotation
// needs to be performed in reverse order to what you
// might normally expect
// See: https://bugreports.qt.io/browse/QTBUG-20752
matrix.translate(0.0f, 0.0f, -1.65f); // Camera position
matrix.translate(m_translateX, m_translateY, m_translateZ); // User camera position adjustment
matrix.rotate(m_rotX, 1.0f, 0.0f, 0.0f); // User rotation
matrix.rotate(m_rotY, 0.0f, 1.0f, 0.0f);
matrix.rotate(m_rotZ, 0.0f, 0.0f, 1.0f);
matrix.scale(m_scaleX, m_scaleY, m_scaleZ * m_userScaleZ);
matrix.scale(m_scaleX, m_scaleY, m_scaleZ * m_userScaleZ); // Scaling
matrix.translate(-0.5f, -0.5f, 0.0f); // Centre at origin for correct rotation
applyPerspective(matrix);
}
void GLShaderSpectrogram::applyPerspective(QMatrix4x4 &matrix)

Wyświetl plik

@ -40,7 +40,7 @@ public:
void initColorMapTexture(const QString &colorMapName);
void initTexture(const QImage& image);
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels);
void drawSurface(SpectrumSettings::SpectrogramStyle style, float textureOffset, bool invert);
void drawSurface(SpectrumSettings::SpectrogramStyle style, const QMatrix4x4& vertexTransform, float textureOffset, bool invert);
void cleanup();
void translateX(float distance);
void translateY(float distance);
@ -61,7 +61,7 @@ public:
void lightRotateX(float degrees);
void lightRotateY(float degrees);
void lightRotateZ(float degrees);
void applyScaleRotate(QMatrix4x4 &matrix);
void applyTransform(QMatrix4x4 &matrix);
void applyPerspective(QMatrix4x4 &matrix);
private:

Wyświetl plik

@ -872,13 +872,10 @@ void GLSpectrum::paintGL()
glFunctions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
QMatrix4x4 spectrogramGridMatrix;
spectrogramGridMatrix.translate(0.0f, 0.0f, -1.65f);
m_glShaderSpectrogram.applyScaleRotate(spectrogramGridMatrix);
spectrogramGridMatrix.translate(-0.5f, -0.5f, 0.0f);
m_glShaderSpectrogram.applyPerspective(spectrogramGridMatrix);
if (m_display3DSpectrogram)
{
m_glShaderSpectrogram.applyTransform(spectrogramGridMatrix);
// paint 3D spectrogram
if (m_3DSpectrogramTexturePos + m_3DSpectrogramBufferPos < m_3DSpectrogramTextureHeight)
{
@ -900,7 +897,7 @@ void GLSpectrum::paintGL()
// Temporarily reduce viewport to waterfall area so anything outside is clipped
glFunctions->glViewport(0, m_3DSpectrogramBottom, width(), m_waterfallHeight);
m_glShaderSpectrogram.drawSurface(m_3DSpectrogramStyle, prop_y, m_invertedWaterfall);
m_glShaderSpectrogram.drawSurface(m_3DSpectrogramStyle, spectrogramGridMatrix, prop_y, m_invertedWaterfall);
glFunctions->glViewport(0, 0, width(), height());
}
else if (m_displayWaterfall)
@ -1168,15 +1165,15 @@ void GLSpectrum::paintGL()
{
glFunctions->glViewport(0, m_3DSpectrogramBottom, width(), m_waterfallHeight);
{
float l = m_spectrogramTimePixmap.width() / (float) width();
float r = m_rightMargin / (float) width();
float h = m_frequencyPixmap.height() / (float) m_waterfallHeight;
GLfloat l = m_spectrogramTimePixmap.width() / (GLfloat) width();
GLfloat r = m_rightMargin / (GLfloat) width();
GLfloat h = m_frequencyPixmap.height() / (GLfloat) m_waterfallHeight;
GLfloat vtx1[] = {
-l, -h,
1+r, -h,
1+r, 0,
-l, 0
-l, -h,
1.0f+r, -h,
1.0f+r, 0.0f,
-l, 0.0f
};
GLfloat tex1[] = {
0, 1,
@ -1189,14 +1186,14 @@ void GLSpectrum::paintGL()
}
{
float w = m_spectrogramTimePixmap.width() / (float) width();
float h = (m_bottomMargin/2) / (float) m_waterfallHeight; // m_bottomMargin is fm.ascent
GLfloat w = m_spectrogramTimePixmap.width() / (GLfloat) width();
GLfloat h = (m_bottomMargin/2) / (GLfloat) m_waterfallHeight; // m_bottomMargin is fm.ascent
GLfloat vtx1[] = {
-w, 0.0-h,
0, 0.0-h,
0, 1.0+h,
-w, 1.0+h
-w, 0.0f-h,
0.0f, 0.0f-h,
0.0f, 1.0f+h,
-w, 1.0f+h
};
GLfloat tex1[] = {
0, 1,
@ -1209,14 +1206,14 @@ void GLSpectrum::paintGL()
}
{
float w = m_spectrogramPowerPixmap.width() / (float) width();
float h = m_topMargin / (float) m_spectrogramPowerPixmap.height();
GLfloat w = m_spectrogramPowerPixmap.width() / (GLfloat) width();
GLfloat h = m_topMargin / (GLfloat) m_spectrogramPowerPixmap.height();
GLfloat vtx1[] = {
-w, 1.0, 0.0,
0, 1.0, 0.0,
0, 1.0, 1.0+h,
-w, 1.0, 1.0+h,
-w, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 1.0f+h,
-w, 1.0f, 1.0f+h,
};
GLfloat tex1[] = {
0, 1,