1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 09:18:54 -05:00

Use 2D textures as 1D not supported in Open GL ES on ARM

This commit is contained in:
Jon Beniston 2022-07-21 19:55:31 +01:00
parent bd7fd29de9
commit 08cc6d02f5
2 changed files with 33 additions and 33 deletions

View File

@ -111,9 +111,9 @@ void GLShaderColorMap::initColorMapTextureImmutable(const QString &colorMapName)
{
if (!m_colorMapTexture)
{
m_colorMapTexture = new QOpenGLTexture(QOpenGLTexture::Target1D);
m_colorMapTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_colorMapTexture->setFormat(QOpenGLTexture::RGB32F);
m_colorMapTexture->setSize(256);
m_colorMapTexture->setSize(256, 1);
m_colorMapTexture->allocateStorage();
m_colorMapTexture->setMinificationFilter(QOpenGLTexture::Linear);
m_colorMapTexture->setMagnificationFilter(QOpenGLTexture::Linear);
@ -137,18 +137,18 @@ void GLShaderColorMap::initColorMapTextureMutable(const QString &colorMapName)
}
glGenTextures(1, &m_colorMapTextureId);
glBindTexture(GL_TEXTURE_1D, m_colorMapTextureId);
glBindTexture(GL_TEXTURE_2D, m_colorMapTextureId); // Use 2D texture as 1D not supported in OpenGL ES on ARM
GLfloat *colorMap = (GLfloat *)ColorMap::getColorMap(colorMapName);
if (colorMap) {
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_RGB, GL_FLOAT, colorMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 1, 0, GL_RGB, GL_FLOAT, colorMap);
} else {
qDebug() << "GLShaderColorMap::initColorMapTextureMutable: colorMap " << colorMapName << " not supported";
}
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, QOpenGLTexture::Repeat);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, QOpenGLTexture::Repeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, QOpenGLTexture::Repeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, QOpenGLTexture::Repeat);
}
void GLShaderColorMap::drawSurfaceStrip(const QMatrix4x4& transformMatrix, GLfloat *vertices, int nbVertices, float scale, float alpha)
@ -263,10 +263,10 @@ const QString GLShaderColorMap::m_vertexShaderSourceColorMap = QString(
const QString GLShaderColorMap::m_fragmentShaderSourceColorMap2 = QString(
"uniform float alpha;\n"
"uniform float scale;\n"
"uniform highp sampler1D colorMap;\n"
"uniform highp sampler2D colorMap;\n"
"varying float y;\n"
"void main() {\n"
" gl_FragColor = vec4(texture1D(colorMap, 1.0-(y/scale)).rgb, alpha);\n"
" gl_FragColor = vec4(texture2D(colorMap, vec2(1.0-(y/scale), 0)).rgb, alpha);\n"
"}\n"
);
@ -274,10 +274,10 @@ const QString GLShaderColorMap::m_fragmentShaderSourceColorMap = QString(
"#version 330\n"
"uniform float alpha;\n"
"uniform float scale;\n"
"uniform sampler1D colorMap;\n"
"uniform sampler2D colorMap;\n"
"in float y;\n"
"out vec4 fragColor;\n"
"void main() {\n"
" fragColor = vec4(texture(colorMap, 1.0-(y/scale)).rgb, alpha);\n"
" fragColor = vec4(texture(colorMap, vec2(1.0-(y/scale), 0)).rgb, alpha);\n"
"}\n"
);

View File

@ -240,9 +240,9 @@ void GLShaderSpectrogram::initColorMapTextureImmutable(const QString &colorMapNa
{
if (!m_colorMapTexture)
{
m_colorMapTexture = new QOpenGLTexture(QOpenGLTexture::Target1D);
m_colorMapTexture = new QOpenGLTexture(QOpenGLTexture::Target2D);
m_colorMapTexture->setFormat(QOpenGLTexture::RGB32F);
m_colorMapTexture->setSize(256);
m_colorMapTexture->setSize(256, 1);
m_colorMapTexture->allocateStorage();
m_colorMapTexture->setMinificationFilter(QOpenGLTexture::Linear);
m_colorMapTexture->setMagnificationFilter(QOpenGLTexture::Linear);
@ -266,18 +266,18 @@ void GLShaderSpectrogram::initColorMapTextureMutable(const QString &colorMapName
}
glGenTextures(1, &m_colorMapTextureId);
glBindTexture(GL_TEXTURE_1D, m_colorMapTextureId);
glBindTexture(GL_TEXTURE_2D, m_colorMapTextureId); // Use 2D texture as 1D not supported in OpenGL ES on ARM
GLfloat *colorMap = (GLfloat *)ColorMap::getColorMap(colorMapName);
if (colorMap) {
glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_RGB, GL_FLOAT, colorMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 1, 0, GL_RGB, GL_FLOAT, colorMap);
} else {
qDebug() << "GLShaderSpectrogram::initColorMapTextureMutable: colorMap " << colorMapName << " not supported";
}
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, QOpenGLTexture::Repeat);
glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, QOpenGLTexture::Repeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, QOpenGLTexture::Repeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, QOpenGLTexture::Repeat);
}
void GLShaderSpectrogram::initTexture(const QImage& image)
@ -412,7 +412,7 @@ void GLShaderSpectrogram::drawSurface(SpectrumSettings::SpectrogramStyle style,
{
glBindTexture(GL_TEXTURE_2D, m_textureId);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_1D, m_colorMapTextureId);
glBindTexture(GL_TEXTURE_2D, m_colorMapTextureId);
glActiveTexture(GL_TEXTURE0);
}
@ -786,7 +786,7 @@ const QString GLShaderSpectrogram::m_fragmentShaderShaded = QString(
"in vec3 normal;\n"
"in float lightDistance2;\n"
"out vec4 fragColor;\n"
"uniform sampler1D colorMap;\n"
"uniform sampler2D colorMap;\n"
"uniform vec3 lightDir;\n"
"void main(void) {\n"
" float factor;\n"
@ -796,9 +796,9 @@ const QString GLShaderSpectrogram::m_fragmentShaderShaded = QString(
" factor = 0.5;\n"
" float ambient = 0.4;\n"
" vec3 color;\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"
" color.r = texture(colorMap, vec2(coord2.z, 0)).r;\n"
" color.g = texture(colorMap, vec2(coord2.z, 0)).g;\n"
" color.b = texture(colorMap, vec2(coord2.z, 0)).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"
@ -812,16 +812,16 @@ const QString GLShaderSpectrogram::m_fragmentShaderShaded = QString(
const QString GLShaderSpectrogram::m_fragmentShaderSimple2 = QString(
"varying vec4 coord;\n"
"uniform float brightness;\n"
"uniform sampler1D colorMap;\n"
"uniform sampler2D colorMap;\n"
"void main(void) {\n"
" float factor;\n"
" if (gl_FrontFacing)\n"
" factor = 1.0;\n"
" else\n"
" factor = 0.5;\n"
" gl_FragColor[0] = texture1D(colorMap, coord.z).r * brightness * factor;\n"
" gl_FragColor[1] = texture1D(colorMap, coord.z).g * brightness * factor;\n"
" gl_FragColor[2] = texture1D(colorMap, coord.z).b * brightness * factor;\n"
" gl_FragColor[0] = texture2D(colorMap, vec2(coord.z, 0)).r * brightness * factor;\n"
" gl_FragColor[1] = texture2D(colorMap, vec2(coord.z, 0)).g * brightness * factor;\n"
" gl_FragColor[2] = texture2D(colorMap, vec2(coord.z, 0)).b * brightness * factor;\n"
" gl_FragColor[3] = 1.0;\n"
"}\n"
);
@ -831,16 +831,16 @@ const QString GLShaderSpectrogram::m_fragmentShaderSimple = QString(
"in vec4 coord;\n"
"out vec4 fragColor;\n"
"uniform float brightness;\n"
"uniform sampler1D colorMap;\n"
"uniform sampler2D 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[0] = texture(colorMap, vec2(coord.z, 0)).r * brightness * factor;\n"
" fragColor[1] = texture(colorMap, vec2(coord.z, 0)).g * brightness * factor;\n"
" fragColor[2] = texture(colorMap, vec2(coord.z, 0)).b * brightness * factor;\n"
" fragColor[3] = 1.0;\n"
"}\n"
);