mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-15 12:51:49 -05:00
Add OpenGL shaders using OpenGL 3.3 syntax for MacOS which doesn't support version 2 syntax wth 4.2 context
This commit is contained in:
parent
c135affb6a
commit
e13e919012
@ -156,6 +156,7 @@ void GLScope::newTraces(std::vector<float *> *traces, int traceIndex, std::vecto
|
||||
void GLScope::initializeGL()
|
||||
{
|
||||
QOpenGLContext *glCurrentContext = QOpenGLContext::currentContext();
|
||||
float openGLVersion = 0.0f;
|
||||
|
||||
if (glCurrentContext)
|
||||
{
|
||||
@ -165,6 +166,8 @@ void GLScope::initializeGL()
|
||||
<< " major: " << (QOpenGLContext::currentContext()->format()).majorVersion()
|
||||
<< " minor: " << (QOpenGLContext::currentContext()->format()).minorVersion()
|
||||
<< " ES: " << (QOpenGLContext::currentContext()->isOpenGLES() ? "yes" : "no");
|
||||
openGLVersion = (QOpenGLContext::currentContext()->format()).majorVersion()
|
||||
+ ((QOpenGLContext::currentContext()->format()).minorVersion() / 10.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -205,14 +208,14 @@ void GLScope::initializeGL()
|
||||
glFunctions->initializeOpenGLFunctions();
|
||||
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
m_glShaderSimple.initializeGL();
|
||||
m_glShaderColors.initializeGL();
|
||||
m_glShaderLeft1Scale.initializeGL();
|
||||
m_glShaderBottom1Scale.initializeGL();
|
||||
m_glShaderLeft2Scale.initializeGL();
|
||||
m_glShaderBottom2Scale.initializeGL();
|
||||
m_glShaderPowerOverlay.initializeGL();
|
||||
m_glShaderTextOverlay.initializeGL();
|
||||
m_glShaderSimple.initializeGL(openGLVersion);
|
||||
m_glShaderColors.initializeGL(openGLVersion);
|
||||
m_glShaderLeft1Scale.initializeGL(openGLVersion);
|
||||
m_glShaderBottom1Scale.initializeGL(openGLVersion);
|
||||
m_glShaderLeft2Scale.initializeGL(openGLVersion);
|
||||
m_glShaderBottom2Scale.initializeGL(openGLVersion);
|
||||
m_glShaderPowerOverlay.initializeGL(openGLVersion);
|
||||
m_glShaderTextOverlay.initializeGL(openGLVersion);
|
||||
}
|
||||
|
||||
void GLScope::resizeGL(int width, int height)
|
||||
|
@ -36,17 +36,28 @@ GLShaderColors::~GLShaderColors()
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void GLShaderColors::initializeGL()
|
||||
void GLShaderColors::initializeGL(float openGLVersion)
|
||||
{
|
||||
m_program = new QOpenGLShaderProgram;
|
||||
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple)) {
|
||||
qDebug() << "GLShaderColors::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceColored)) {
|
||||
qDebug() << "GLShaderColors::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
if (openGLVersion >= 3.3)
|
||||
{
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple)) {
|
||||
qDebug() << "GLShaderColors::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceColored)) {
|
||||
qDebug() << "GLShaderColors::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple2)) {
|
||||
qDebug() << "GLShaderColors::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceColored2)) {
|
||||
qDebug() << "GLShaderColors::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
}
|
||||
|
||||
m_program->bindAttributeLocation("vertex", 0);
|
||||
m_program->bindAttributeLocation("v_color", 1);
|
||||
@ -118,7 +129,7 @@ void GLShaderColors::cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
const QString GLShaderColors::m_vertexShaderSourceSimple = QString(
|
||||
const QString GLShaderColors::m_vertexShaderSourceSimple2 = QString(
|
||||
"uniform highp mat4 uMatrix;\n"
|
||||
"attribute highp vec4 vertex;\n"
|
||||
"attribute vec3 v_color;\n"
|
||||
@ -129,10 +140,32 @@ const QString GLShaderColors::m_vertexShaderSourceSimple = QString(
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderColors::m_fragmentShaderSourceColored = QString(
|
||||
const QString GLShaderColors::m_vertexShaderSourceSimple = QString(
|
||||
"#version 330\n"
|
||||
"uniform highp mat4 uMatrix;\n"
|
||||
"in highp vec4 vertex;\n"
|
||||
"in vec3 v_color;\n"
|
||||
"out vec3 f_color;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = uMatrix * vertex;\n"
|
||||
" f_color = v_color;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderColors::m_fragmentShaderSourceColored2 = QString(
|
||||
"uniform mediump float uAlpha;\n"
|
||||
"varying vec3 f_color;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = vec4(f_color.r, f_color.g, f_color.b, uAlpha);\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderColors::m_fragmentShaderSourceColored = QString(
|
||||
"#version 330\n"
|
||||
"uniform mediump float uAlpha;\n"
|
||||
"in vec3 f_color;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"void main() {\n"
|
||||
" fragColor = vec4(f_color.r, f_color.g, f_color.b, uAlpha);\n"
|
||||
"}\n"
|
||||
);
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
GLShaderColors();
|
||||
~GLShaderColors();
|
||||
|
||||
void initializeGL();
|
||||
void initializeGL(float openGLVersion);
|
||||
void drawPoints(const QMatrix4x4& transformMatrix, GLfloat *vertices, GLfloat *colors, GLfloat alpha, int nbVertices);
|
||||
void drawPolyline(const QMatrix4x4& transformMatrix, GLfloat *vertices, GLfloat *colors, GLfloat alpha, int nbVertices);
|
||||
void drawSegments(const QMatrix4x4& transformMatrix, GLfloat *vertices, GLfloat *colors, GLfloat alpha, int nbVertices);
|
||||
@ -51,7 +51,9 @@ private:
|
||||
QOpenGLShaderProgram *m_program;
|
||||
int m_matrixLoc;
|
||||
int m_alphaLoc;
|
||||
static const QString m_vertexShaderSourceSimple2;
|
||||
static const QString m_vertexShaderSourceSimple;
|
||||
static const QString m_fragmentShaderSourceColored2;
|
||||
static const QString m_fragmentShaderSourceColored;
|
||||
};
|
||||
|
||||
|
@ -36,17 +36,28 @@ GLShaderSimple::~GLShaderSimple()
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void GLShaderSimple::initializeGL()
|
||||
void GLShaderSimple::initializeGL(float openGLVersion)
|
||||
{
|
||||
m_program = new QOpenGLShaderProgram;
|
||||
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple)) {
|
||||
qDebug() << "GLShaderSimple::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceColored)) {
|
||||
qDebug() << "GLShaderSimple::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
if (openGLVersion >= 3.3)
|
||||
{
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple)) {
|
||||
qDebug() << "GLShaderSimple::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceColored)) {
|
||||
qDebug() << "GLShaderSimple::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceSimple2)) {
|
||||
qDebug() << "GLShaderSimple::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceColored2)) {
|
||||
qDebug() << "GLShaderSimple::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
}
|
||||
|
||||
m_program->bindAttributeLocation("vertex", 0);
|
||||
|
||||
@ -110,7 +121,7 @@ void GLShaderSimple::cleanup()
|
||||
}
|
||||
}
|
||||
|
||||
const QString GLShaderSimple::m_vertexShaderSourceSimple = QString(
|
||||
const QString GLShaderSimple::m_vertexShaderSourceSimple2 = QString(
|
||||
"uniform highp mat4 uMatrix;\n"
|
||||
"attribute highp vec4 vertex;\n"
|
||||
"void main() {\n"
|
||||
@ -118,9 +129,27 @@ const QString GLShaderSimple::m_vertexShaderSourceSimple = QString(
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderSimple::m_fragmentShaderSourceColored = QString(
|
||||
const QString GLShaderSimple::m_vertexShaderSourceSimple = QString(
|
||||
"#version 330\n"
|
||||
"uniform highp mat4 uMatrix;\n"
|
||||
"in highp vec4 vertex;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = uMatrix * vertex;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderSimple::m_fragmentShaderSourceColored2 = QString(
|
||||
"uniform mediump vec4 uColour;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = uColour;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderSimple::m_fragmentShaderSourceColored = QString(
|
||||
"#version 330\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"uniform mediump vec4 uColour;\n"
|
||||
"void main() {\n"
|
||||
" fragColor = uColour;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
GLShaderSimple();
|
||||
~GLShaderSimple();
|
||||
|
||||
void initializeGL();
|
||||
void initializeGL(float openGLVersion);
|
||||
void drawPoints(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents=2);
|
||||
void drawPolyline(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents=2);
|
||||
void drawSegments(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents=2);
|
||||
@ -48,7 +48,9 @@ private:
|
||||
QOpenGLShaderProgram *m_program;
|
||||
int m_matrixLoc;
|
||||
int m_colorLoc;
|
||||
static const QString m_vertexShaderSourceSimple2;
|
||||
static const QString m_vertexShaderSourceSimple;
|
||||
static const QString m_fragmentShaderSourceColored2;
|
||||
static const QString m_fragmentShaderSourceColored;
|
||||
};
|
||||
|
||||
|
@ -38,7 +38,7 @@ GLShaderSpectrogram::GLShaderSpectrogram() :
|
||||
m_programForLocs(nullptr),
|
||||
m_textureTransformLoc(0),
|
||||
m_vertexTransformLoc(0),
|
||||
m_textureLoc(0),
|
||||
m_dataTextureLoc(0),
|
||||
m_limitLoc(0),
|
||||
m_brightnessLoc(0),
|
||||
m_colorMapLoc(0),
|
||||
@ -75,35 +75,51 @@ GLShaderSpectrogram::~GLShaderSpectrogram()
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void GLShaderSpectrogram::initializeGL()
|
||||
void GLShaderSpectrogram::initializeGL(float openGLVersion)
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
m_useImmutableStorage = useImmutableStorage();
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: m_useImmutableStorage: " << m_useImmutableStorage;
|
||||
|
||||
m_programShaded = new QOpenGLShaderProgram;
|
||||
if (!m_programShaded->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShader)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in vertex shader: " << m_programShaded->log();
|
||||
}
|
||||
if (!m_programShaded->addShaderFromSourceCode(QOpenGLShader::Geometry, m_geometryShader)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in geometry shader: " << m_programShaded->log();
|
||||
}
|
||||
if (!m_programShaded->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderShaded)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in fragment shader: " << m_programShaded->log();
|
||||
}
|
||||
if (!m_programShaded->link()) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error linking shader: " << m_programShaded->log();
|
||||
}
|
||||
if (openGLVersion >= 3.3)
|
||||
{
|
||||
m_programShaded = new QOpenGLShaderProgram;
|
||||
if (!m_programShaded->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShader)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in vertex shader: " << m_programShaded->log();
|
||||
}
|
||||
if (!m_programShaded->addShaderFromSourceCode(QOpenGLShader::Geometry, m_geometryShader)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in geometry shader: " << m_programShaded->log();
|
||||
}
|
||||
if (!m_programShaded->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderShaded)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in fragment shader: " << m_programShaded->log();
|
||||
}
|
||||
if (!m_programShaded->link()) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error linking shader: " << m_programShaded->log();
|
||||
}
|
||||
|
||||
m_programSimple = new QOpenGLShaderProgram;
|
||||
if (!m_programSimple->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShader)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in vertex shader: " << m_programSimple->log();
|
||||
m_programSimple = new QOpenGLShaderProgram;
|
||||
if (!m_programSimple->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShader)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in vertex shader: " << m_programSimple->log();
|
||||
}
|
||||
if (!m_programSimple->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSimple)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in fragment shader: " << m_programSimple->log();
|
||||
}
|
||||
if (!m_programSimple->link()) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error linking shader: " << m_programSimple->log();
|
||||
}
|
||||
}
|
||||
if (!m_programSimple->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSimple)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in fragment shader: " << m_programSimple->log();
|
||||
}
|
||||
if (!m_programSimple->link()) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error linking shader: " << m_programSimple->log();
|
||||
else
|
||||
{
|
||||
m_programSimple = new QOpenGLShaderProgram;
|
||||
if (!m_programSimple->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShader2)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in vertex shader: " << m_programSimple->log();
|
||||
}
|
||||
if (!m_programSimple->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSimple2)) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error in fragment shader: " << m_programSimple->log();
|
||||
}
|
||||
if (!m_programSimple->link()) {
|
||||
qDebug() << "GLShaderSpectrogram::initializeGL: error linking shader: " << m_programSimple->log();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -324,6 +340,9 @@ void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style,
|
||||
} else {
|
||||
program = m_programSimple;
|
||||
}
|
||||
if (!program) {
|
||||
return;
|
||||
}
|
||||
|
||||
float rot = invert ? 1.0 : -1.0;
|
||||
QMatrix4x4 textureTransform(
|
||||
@ -339,7 +358,7 @@ void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style,
|
||||
{
|
||||
m_textureTransformLoc = program->uniformLocation("textureTransform");
|
||||
m_vertexTransformLoc = program->uniformLocation("vertexTransform");
|
||||
m_textureLoc = program->uniformLocation("texture");
|
||||
m_dataTextureLoc = program->uniformLocation("dataTexture");
|
||||
m_limitLoc = program->uniformLocation("limit");
|
||||
m_brightnessLoc = program->uniformLocation("brightness");
|
||||
m_colorMapLoc = program->uniformLocation("colorMap");
|
||||
@ -366,7 +385,7 @@ void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style,
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
program->setUniformValue(m_textureLoc, 0); // set uniform to texture unit?
|
||||
program->setUniformValue(m_dataTextureLoc, 0); // set uniform to texture unit?
|
||||
program->setUniformValue(m_colorMapLoc, 1);
|
||||
|
||||
program->setUniformValue(m_limitLoc, 1.5f*1.0f/(float)(m_gridElements));
|
||||
@ -664,18 +683,36 @@ void GLShaderSpectrogram::applyPerspective(QMatrix4x4 &matrix)
|
||||
|
||||
// The clamp is to prevent old data affecting new data (And vice versa),
|
||||
// which can happen where the texture repeats - might be a better way to do it
|
||||
const QString GLShaderSpectrogram::m_vertexShader = QString(
|
||||
const QString GLShaderSpectrogram::m_vertexShader2 = QString(
|
||||
"attribute vec2 coord2d;\n"
|
||||
"varying vec4 coord;\n"
|
||||
"varying float lightDistance;\n"
|
||||
"uniform mat4 textureTransform;\n"
|
||||
"uniform mat4 vertexTransform;\n"
|
||||
"uniform sampler2D texture;\n"
|
||||
"uniform sampler2D dataTexture;\n"
|
||||
"uniform float limit;\n"
|
||||
"uniform vec3 lightPos;\n"
|
||||
"void main(void) {\n"
|
||||
" coord = textureTransform * vec4(clamp(coord2d, limit, 1.0-limit), 0, 1);\n"
|
||||
" coord.z = (texture2D(texture, coord.xy).r);\n"
|
||||
" coord.z = (texture2D(dataTexture, coord.xy).r);\n"
|
||||
" gl_Position = vertexTransform * vec4(coord2d, coord.z, 1);\n"
|
||||
" lightDistance = length(lightPos - gl_Position.xyz);\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderSpectrogram::m_vertexShader = QString(
|
||||
"#version 330\n"
|
||||
"in vec2 coord2d;\n"
|
||||
"out vec4 coord;\n"
|
||||
"out float lightDistance;\n"
|
||||
"uniform mat4 textureTransform;\n"
|
||||
"uniform mat4 vertexTransform;\n"
|
||||
"uniform sampler2D dataTexture;\n"
|
||||
"uniform float limit;\n"
|
||||
"uniform vec3 lightPos;\n"
|
||||
"void main(void) {\n"
|
||||
" coord = textureTransform * vec4(clamp(coord2d, limit, 1.0-limit), 0, 1);\n"
|
||||
" coord.z = (texture(dataTexture, coord.xy).r);\n"
|
||||
" gl_Position = vertexTransform * vec4(coord2d, coord.z, 1);\n"
|
||||
" lightDistance = length(lightPos - gl_Position.xyz);\n"
|
||||
"}\n"
|
||||
@ -709,9 +746,11 @@ const QString GLShaderSpectrogram::m_geometryShader = QString(
|
||||
);
|
||||
|
||||
const QString GLShaderSpectrogram::m_fragmentShaderShaded = QString(
|
||||
"varying vec4 coord2;\n"
|
||||
"varying vec3 normal;\n"
|
||||
"varying float lightDistance2;\n"
|
||||
"#version 330\n"
|
||||
"in vec4 coord2;\n"
|
||||
"in vec3 normal;\n"
|
||||
"in float lightDistance2;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"uniform sampler1D colorMap;\n"
|
||||
"uniform vec3 lightDir;\n"
|
||||
"void main(void) {\n"
|
||||
@ -722,20 +761,20 @@ const QString GLShaderSpectrogram::m_fragmentShaderShaded = QString(
|
||||
" factor = 0.5;\n"
|
||||
" float ambient = 0.4;\n"
|
||||
" vec3 color;\n"
|
||||
" color.r = texture1D(colorMap, coord2.z).r;\n"
|
||||
" color.g = texture1D(colorMap, coord2.z).g;\n"
|
||||
" color.b = texture1D(colorMap, coord2.z).b;\n"
|
||||
" color.r = texture(colorMap, coord2.z).r;\n"
|
||||
" color.g = texture(colorMap, coord2.z).g;\n"
|
||||
" color.b = texture(colorMap, coord2.z).b;\n"
|
||||
" float cosTheta = max(0.0, dot(normal, lightDir));\n"
|
||||
" float d2 = max(1.0, lightDistance2*lightDistance2);\n"
|
||||
" vec3 relection = (ambient * color + color * cosTheta / d2) * factor;\n"
|
||||
" gl_FragColor[0] = relection.r;\n"
|
||||
" gl_FragColor[1] = relection.g;\n"
|
||||
" gl_FragColor[2] = relection.b;\n"
|
||||
" gl_FragColor[3] = 1.0;\n"
|
||||
" fragColor[0] = relection.r;\n"
|
||||
" fragColor[1] = relection.g;\n"
|
||||
" fragColor[2] = relection.b;\n"
|
||||
" fragColor[3] = 1.0;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderSpectrogram::m_fragmentShaderSimple = QString(
|
||||
const QString GLShaderSpectrogram::m_fragmentShaderSimple2 = QString(
|
||||
"varying vec4 coord;\n"
|
||||
"uniform float brightness;\n"
|
||||
"uniform sampler1D colorMap;\n"
|
||||
@ -751,3 +790,22 @@ const QString GLShaderSpectrogram::m_fragmentShaderSimple = QString(
|
||||
" gl_FragColor[3] = 1.0;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderSpectrogram::m_fragmentShaderSimple = QString(
|
||||
"#version 330\n"
|
||||
"in vec4 coord;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"uniform float brightness;\n"
|
||||
"uniform sampler1D colorMap;\n"
|
||||
"void main(void) {\n"
|
||||
" float factor;\n"
|
||||
" if (gl_FrontFacing)\n"
|
||||
" factor = 1.0;\n"
|
||||
" else\n"
|
||||
" factor = 0.5;\n"
|
||||
" fragColor[0] = texture(colorMap, coord.z).r * brightness * factor;\n"
|
||||
" fragColor[1] = texture(colorMap, coord.z).g * brightness * factor;\n"
|
||||
" fragColor[2] = texture(colorMap, coord.z).b * brightness * factor;\n"
|
||||
" fragColor[3] = 1.0;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
GLShaderSpectrogram();
|
||||
~GLShaderSpectrogram();
|
||||
|
||||
void initializeGL();
|
||||
void initializeGL(float openGLVersion);
|
||||
void initColorMapTexture(const QString &colorMapName);
|
||||
void initTexture(const QImage& image);
|
||||
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels);
|
||||
@ -85,7 +85,7 @@ private:
|
||||
QOpenGLShaderProgram *m_programForLocs; // Which program the locations are for
|
||||
int m_textureTransformLoc;
|
||||
int m_vertexTransformLoc;
|
||||
int m_textureLoc;
|
||||
int m_dataTextureLoc;
|
||||
int m_limitLoc;
|
||||
int m_brightnessLoc;
|
||||
int m_colorMapLoc;
|
||||
@ -93,9 +93,11 @@ private:
|
||||
int m_lightPosLoc;
|
||||
|
||||
bool m_useImmutableStorage;
|
||||
static const QString m_vertexShader2;
|
||||
static const QString m_vertexShader;
|
||||
static const QString m_geometryShader;
|
||||
static const QString m_fragmentShaderShaded;
|
||||
static const QString m_fragmentShaderSimple2;
|
||||
static const QString m_fragmentShaderSimple;
|
||||
|
||||
QOpenGLBuffer m_vertexBuf;
|
||||
|
@ -40,21 +40,31 @@ GLShaderTextured::~GLShaderTextured()
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void GLShaderTextured::initializeGL()
|
||||
void GLShaderTextured::initializeGL(float openGLVersion)
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
m_useImmutableStorage = useImmutableStorage();
|
||||
qDebug() << "GLShaderTextured::initializeGL: m_useImmutableStorage: " << m_useImmutableStorage;
|
||||
|
||||
m_program = new QOpenGLShaderProgram;
|
||||
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceTextured)) {
|
||||
qDebug() << "GLShaderTextured::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceTextured)) {
|
||||
qDebug() << "GLShaderTextured::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
m_program = new QOpenGLShaderProgram;
|
||||
if (openGLVersion >= 3.3f)
|
||||
{
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceTextured)) {
|
||||
qDebug() << "GLShaderTextured::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceTextured)) {
|
||||
qDebug() << "GLShaderTextured::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceTextured2)) {
|
||||
qDebug() << "GLShaderTextured::initializeGL: error in vertex shader: " << m_program->log();
|
||||
}
|
||||
if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceTextured2)) {
|
||||
qDebug() << "GLShaderTextured::initializeGL: error in fragment shader: " << m_program->log();
|
||||
}
|
||||
}
|
||||
|
||||
m_program->bindAttributeLocation("vertex", 0);
|
||||
m_program->bindAttributeLocation("texCoord", 1);
|
||||
@ -248,7 +258,7 @@ bool GLShaderTextured::useImmutableStorage()
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString GLShaderTextured::m_vertexShaderSourceTextured = QString(
|
||||
const QString GLShaderTextured::m_vertexShaderSourceTextured2 = QString(
|
||||
"uniform highp mat4 uMatrix;\n"
|
||||
"attribute highp vec4 vertex;\n"
|
||||
"attribute highp vec2 texCoord;\n"
|
||||
@ -259,10 +269,32 @@ const QString GLShaderTextured::m_vertexShaderSourceTextured = QString(
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderTextured::m_fragmentShaderSourceTextured = QString(
|
||||
const QString GLShaderTextured::m_vertexShaderSourceTextured = QString(
|
||||
"#version 330\n"
|
||||
"uniform highp mat4 uMatrix;\n"
|
||||
"in highp vec4 vertex;\n"
|
||||
"in highp vec2 texCoord;\n"
|
||||
"out mediump vec2 texCoordVar;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = uMatrix * vertex;\n"
|
||||
" texCoordVar = texCoord;\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderTextured::m_fragmentShaderSourceTextured2 = QString(
|
||||
"uniform lowp sampler2D uTexture;\n"
|
||||
"varying mediump vec2 texCoordVar;\n"
|
||||
"void main() {\n"
|
||||
" gl_FragColor = texture2D(uTexture, texCoordVar);\n"
|
||||
"}\n"
|
||||
);
|
||||
|
||||
const QString GLShaderTextured::m_fragmentShaderSourceTextured = QString(
|
||||
"#version 330\n"
|
||||
"uniform lowp sampler2D uTexture;\n"
|
||||
"in mediump vec2 texCoordVar;\n"
|
||||
"out vec4 fragColor;\n"
|
||||
"void main() {\n"
|
||||
" fragColor = texture(uTexture, texCoordVar);\n"
|
||||
"}\n"
|
||||
);
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
GLShaderTextured();
|
||||
~GLShaderTextured();
|
||||
|
||||
void initializeGL();
|
||||
void initializeGL(float openGLVersion);
|
||||
void initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
||||
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels);
|
||||
void drawSurface(const QMatrix4x4& transformMatrix, GLfloat* textureCoords, GLfloat *vertices, int nbVertices, int nbComponents=2);
|
||||
@ -59,7 +59,9 @@ private:
|
||||
int m_matrixLoc;
|
||||
int m_textureLoc;
|
||||
bool m_useImmutableStorage;
|
||||
static const QString m_vertexShaderSourceTextured2;
|
||||
static const QString m_vertexShaderSourceTextured;
|
||||
static const QString m_fragmentShaderSourceTextured2;
|
||||
static const QString m_fragmentShaderSourceTextured;
|
||||
};
|
||||
|
||||
|
@ -766,14 +766,18 @@ void GLSpectrum::updateHistogram(const Real *spectrum)
|
||||
void GLSpectrum::initializeGL()
|
||||
{
|
||||
QOpenGLContext *glCurrentContext = QOpenGLContext::currentContext();
|
||||
float openGLVersion = 0.0f;
|
||||
|
||||
if (glCurrentContext)
|
||||
{
|
||||
if (QOpenGLContext::currentContext()->isValid()) {
|
||||
if (QOpenGLContext::currentContext()->isValid())
|
||||
{
|
||||
qDebug() << "GLSpectrum::initializeGL: context:"
|
||||
<< " major: " << (QOpenGLContext::currentContext()->format()).majorVersion()
|
||||
<< " minor: " << (QOpenGLContext::currentContext()->format()).minorVersion()
|
||||
<< " ES: " << (QOpenGLContext::currentContext()->isOpenGLES() ? "yes" : "no");
|
||||
openGLVersion = (QOpenGLContext::currentContext()->format()).majorVersion()
|
||||
+ ((QOpenGLContext::currentContext()->format()).minorVersion() / 10.0);
|
||||
}
|
||||
else {
|
||||
qDebug() << "GLSpectrum::initializeGL: current context is invalid";
|
||||
@ -812,16 +816,16 @@ void GLSpectrum::initializeGL()
|
||||
glFunctions->initializeOpenGLFunctions();
|
||||
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
m_glShaderSimple.initializeGL();
|
||||
m_glShaderLeftScale.initializeGL();
|
||||
m_glShaderFrequencyScale.initializeGL();
|
||||
m_glShaderWaterfall.initializeGL();
|
||||
m_glShaderHistogram.initializeGL();
|
||||
m_glShaderTextOverlay.initializeGL();
|
||||
m_glShaderInfo.initializeGL();
|
||||
m_glShaderSpectrogram.initializeGL();
|
||||
m_glShaderSpectrogramTimeScale.initializeGL();
|
||||
m_glShaderSpectrogramPowerScale.initializeGL();
|
||||
m_glShaderSimple.initializeGL(openGLVersion);
|
||||
m_glShaderLeftScale.initializeGL(openGLVersion);
|
||||
m_glShaderFrequencyScale.initializeGL(openGLVersion);
|
||||
m_glShaderWaterfall.initializeGL(openGLVersion);
|
||||
m_glShaderHistogram.initializeGL(openGLVersion);
|
||||
m_glShaderTextOverlay.initializeGL(openGLVersion);
|
||||
m_glShaderInfo.initializeGL(openGLVersion);
|
||||
m_glShaderSpectrogram.initializeGL(openGLVersion);
|
||||
m_glShaderSpectrogramTimeScale.initializeGL(openGLVersion);
|
||||
m_glShaderSpectrogramPowerScale.initializeGL(openGLVersion);
|
||||
}
|
||||
|
||||
void GLSpectrum::openGLDebug(const QOpenGLDebugMessage &debugMessage)
|
||||
|
@ -327,7 +327,7 @@ This dropdown determines how the 3D Spectrogram data is rendered.
|
||||
- Lines: The data points are connected by lines.
|
||||
- Solid: The data are rendeded as a solid surface with constant illumination.
|
||||
- Outline: The data are rendered as a solid surface with outlines of the polygons highlighted.
|
||||
- Shaded: The data are rendeder as a solid surface with a combination of ambient and diffuse lighting.
|
||||
- Shaded: The data are rendeder as a solid surface with a combination of ambient and diffuse lighting. This requires OpenGL 3.3 or greater.
|
||||
|
||||
<h4>B.5.2: Color Map</h4>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user