mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-23 18:52:28 -04:00
Fix formatting
This commit is contained in:
parent
94f93ee9ad
commit
8c500cf0c6
@ -26,22 +26,22 @@
|
|||||||
#include "gui/glshadersimple.h"
|
#include "gui/glshadersimple.h"
|
||||||
|
|
||||||
GLShaderSimple::GLShaderSimple() :
|
GLShaderSimple::GLShaderSimple() :
|
||||||
m_program(nullptr),
|
m_program(nullptr),
|
||||||
m_vao(nullptr),
|
m_vao(nullptr),
|
||||||
m_verticesBuf(nullptr),
|
m_verticesBuf(nullptr),
|
||||||
m_vertexLoc(0),
|
m_vertexLoc(0),
|
||||||
m_matrixLoc(0),
|
m_matrixLoc(0),
|
||||||
m_colorLoc(0)
|
m_colorLoc(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
GLShaderSimple::~GLShaderSimple()
|
GLShaderSimple::~GLShaderSimple()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::initializeGL(int majorVersion, int minorVersion)
|
void GLShaderSimple::initializeGL(int majorVersion, int minorVersion)
|
||||||
{
|
{
|
||||||
m_program = new QOpenGLShaderProgram;
|
m_program = new QOpenGLShaderProgram;
|
||||||
|
|
||||||
if ((majorVersion > 3) || ((majorVersion == 3) && (minorVersion >= 3)))
|
if ((majorVersion > 3) || ((majorVersion == 3) && (minorVersion >= 3)))
|
||||||
{
|
{
|
||||||
@ -66,16 +66,16 @@ void GLShaderSimple::initializeGL(int majorVersion, int minorVersion)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_program->bindAttributeLocation("vertex", 0);
|
m_program->bindAttributeLocation("vertex", 0);
|
||||||
|
|
||||||
if (!m_program->link()) {
|
if (!m_program->link()) {
|
||||||
qDebug() << "GLShaderSimple::initializeGL: error linking shader: " << m_program->log();
|
qDebug() << "GLShaderSimple::initializeGL: error linking shader: " << m_program->log();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
m_vertexLoc = m_program->attributeLocation("vertex");
|
m_vertexLoc = m_program->attributeLocation("vertex");
|
||||||
m_matrixLoc = m_program->uniformLocation("uMatrix");
|
m_matrixLoc = m_program->uniformLocation("uMatrix");
|
||||||
m_colorLoc = m_program->uniformLocation("uColour");
|
m_colorLoc = m_program->uniformLocation("uColour");
|
||||||
if (m_vao)
|
if (m_vao)
|
||||||
{
|
{
|
||||||
m_verticesBuf = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
|
m_verticesBuf = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
|
||||||
@ -83,7 +83,7 @@ void GLShaderSimple::initializeGL(int majorVersion, int minorVersion)
|
|||||||
m_verticesBuf->create();
|
m_verticesBuf->create();
|
||||||
m_vao->release();
|
m_vao->release();
|
||||||
}
|
}
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::drawPoints(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderSimple::drawPoints(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
@ -93,30 +93,30 @@ void GLShaderSimple::drawPoints(const QMatrix4x4& transformMatrix, const QVector
|
|||||||
|
|
||||||
void GLShaderSimple::drawPolyline(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderSimple::drawPolyline(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
draw(GL_LINE_STRIP, transformMatrix, color, vertices, nbVertices, nbComponents);
|
draw(GL_LINE_STRIP, transformMatrix, color, vertices, nbVertices, nbComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::drawSegments(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderSimple::drawSegments(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
draw(GL_LINES, transformMatrix, color, vertices, nbVertices, nbComponents);
|
draw(GL_LINES, transformMatrix, color, vertices, nbVertices, nbComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::drawContour(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderSimple::drawContour(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
draw(GL_LINE_LOOP, transformMatrix, color, vertices, nbVertices, nbComponents);
|
draw(GL_LINE_LOOP, transformMatrix, color, vertices, nbVertices, nbComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::drawSurface(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderSimple::drawSurface(const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
draw(GL_TRIANGLE_FAN, transformMatrix, color, vertices, nbVertices, nbComponents);
|
draw(GL_TRIANGLE_FAN, transformMatrix, color, vertices, nbVertices, nbComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::draw(unsigned int mode, const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderSimple::draw(unsigned int mode, const QMatrix4x4& transformMatrix, const QVector4D& color, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
m_program->setUniformValue(m_matrixLoc, transformMatrix);
|
m_program->setUniformValue(m_matrixLoc, transformMatrix);
|
||||||
m_program->setUniformValue(m_colorLoc, color);
|
m_program->setUniformValue(m_colorLoc, color);
|
||||||
if (m_vao)
|
if (m_vao)
|
||||||
{
|
{
|
||||||
m_vao->bind();
|
m_vao->bind();
|
||||||
@ -128,21 +128,21 @@ void GLShaderSimple::draw(unsigned int mode, const QMatrix4x4& transformMatrix,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f->glEnableVertexAttribArray(m_vertexLoc); // vertex
|
f->glEnableVertexAttribArray(m_vertexLoc); // vertex
|
||||||
f->glVertexAttribPointer(m_vertexLoc, nbComponents, GL_FLOAT, GL_FALSE, 0, vertices);
|
f->glVertexAttribPointer(m_vertexLoc, nbComponents, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
f->glEnable(GL_BLEND);
|
f->glEnable(GL_BLEND);
|
||||||
f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
f->glLineWidth(1.0f);
|
f->glLineWidth(1.0f);
|
||||||
f->glDrawArrays(mode, 0, nbVertices);
|
f->glDrawArrays(mode, 0, nbVertices);
|
||||||
|
|
||||||
if (m_vao) {
|
if (m_vao) {
|
||||||
m_vao->release();
|
m_vao->release();
|
||||||
} else {
|
} else {
|
||||||
f->glDisableVertexAttribArray(m_vertexLoc);
|
f->glDisableVertexAttribArray(m_vertexLoc);
|
||||||
}
|
}
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderSimple::cleanup()
|
void GLShaderSimple::cleanup()
|
||||||
@ -156,34 +156,34 @@ void GLShaderSimple::cleanup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString GLShaderSimple::m_vertexShaderSourceSimple2 = QString(
|
const QString GLShaderSimple::m_vertexShaderSourceSimple2 = QString(
|
||||||
"uniform highp mat4 uMatrix;\n"
|
"uniform highp mat4 uMatrix;\n"
|
||||||
"attribute highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = uMatrix * vertex;\n"
|
" gl_Position = uMatrix * vertex;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderSimple::m_vertexShaderSourceSimple = QString(
|
const QString GLShaderSimple::m_vertexShaderSourceSimple = QString(
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
"uniform highp mat4 uMatrix;\n"
|
"uniform highp mat4 uMatrix;\n"
|
||||||
"in highp vec4 vertex;\n"
|
"in highp vec4 vertex;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = uMatrix * vertex;\n"
|
" gl_Position = uMatrix * vertex;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderSimple::m_fragmentShaderSourceColored2 = QString(
|
const QString GLShaderSimple::m_fragmentShaderSourceColored2 = QString(
|
||||||
"uniform mediump vec4 uColour;\n"
|
"uniform mediump vec4 uColour;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_FragColor = uColour;\n"
|
" gl_FragColor = uColour;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderSimple::m_fragmentShaderSourceColored = QString(
|
const QString GLShaderSimple::m_fragmentShaderSourceColored = QString(
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 fragColor;\n"
|
||||||
"uniform mediump vec4 uColour;\n"
|
"uniform mediump vec4 uColour;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" fragColor = uColour;\n"
|
" fragColor = uColour;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
@ -27,22 +27,22 @@
|
|||||||
#include "gui/glshadertextured.h"
|
#include "gui/glshadertextured.h"
|
||||||
|
|
||||||
GLShaderTextured::GLShaderTextured() :
|
GLShaderTextured::GLShaderTextured() :
|
||||||
m_program(nullptr),
|
m_program(nullptr),
|
||||||
m_vao(nullptr),
|
m_vao(nullptr),
|
||||||
m_verticesBuf(nullptr),
|
m_verticesBuf(nullptr),
|
||||||
m_textureCoordsBuf(nullptr),
|
m_textureCoordsBuf(nullptr),
|
||||||
m_texture(nullptr),
|
m_texture(nullptr),
|
||||||
m_textureId(0),
|
m_textureId(0),
|
||||||
m_vertexLoc(0),
|
m_vertexLoc(0),
|
||||||
m_texCoordLoc(0),
|
m_texCoordLoc(0),
|
||||||
m_matrixLoc(0),
|
m_matrixLoc(0),
|
||||||
m_textureLoc(0),
|
m_textureLoc(0),
|
||||||
m_useImmutableStorage(true)
|
m_useImmutableStorage(true)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
GLShaderTextured::~GLShaderTextured()
|
GLShaderTextured::~GLShaderTextured()
|
||||||
{
|
{
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::initializeGL(int majorVersion, int minorVersion)
|
void GLShaderTextured::initializeGL(int majorVersion, int minorVersion)
|
||||||
@ -75,18 +75,18 @@ void GLShaderTextured::initializeGL(int majorVersion, int minorVersion)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_program->bindAttributeLocation("vertex", 0);
|
m_program->bindAttributeLocation("vertex", 0);
|
||||||
m_program->bindAttributeLocation("texCoord", 1);
|
m_program->bindAttributeLocation("texCoord", 1);
|
||||||
|
|
||||||
if (!m_program->link()) {
|
if (!m_program->link()) {
|
||||||
qDebug() << "GLShaderTextured::initializeGL: error linking shader: " << m_program->log();
|
qDebug() << "GLShaderTextured::initializeGL: error linking shader: " << m_program->log();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
m_vertexLoc = m_program->attributeLocation("vertex");
|
m_vertexLoc = m_program->attributeLocation("vertex");
|
||||||
m_texCoordLoc = m_program->attributeLocation("texCoord");
|
m_texCoordLoc = m_program->attributeLocation("texCoord");
|
||||||
m_matrixLoc = m_program->uniformLocation("uMatrix");
|
m_matrixLoc = m_program->uniformLocation("uMatrix");
|
||||||
m_textureLoc = m_program->uniformLocation("uTexture");
|
m_textureLoc = m_program->uniformLocation("uTexture");
|
||||||
if (m_vao)
|
if (m_vao)
|
||||||
{
|
{
|
||||||
m_verticesBuf = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
|
m_verticesBuf = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
|
||||||
@ -97,7 +97,7 @@ void GLShaderTextured::initializeGL(int majorVersion, int minorVersion)
|
|||||||
m_textureCoordsBuf->create();
|
m_textureCoordsBuf->create();
|
||||||
m_vao->release();
|
m_vao->release();
|
||||||
}
|
}
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
void GLShaderTextured::initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
||||||
@ -111,34 +111,34 @@ void GLShaderTextured::initTexture(const QImage& image, QOpenGLTexture::WrapMode
|
|||||||
|
|
||||||
void GLShaderTextured::initTextureImmutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
void GLShaderTextured::initTextureImmutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
||||||
{
|
{
|
||||||
if (m_texture) {
|
if (m_texture) {
|
||||||
delete m_texture;
|
delete m_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_texture = new QOpenGLTexture(image);
|
m_texture = new QOpenGLTexture(image);
|
||||||
|
|
||||||
m_texture->setMinificationFilter(QOpenGLTexture::Linear);
|
m_texture->setMinificationFilter(QOpenGLTexture::Linear);
|
||||||
m_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
m_texture->setMagnificationFilter(QOpenGLTexture::Linear);
|
||||||
m_texture->setWrapMode(wrapMode);
|
m_texture->setWrapMode(wrapMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::initTextureMutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
void GLShaderTextured::initTextureMutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode)
|
||||||
{
|
{
|
||||||
if (m_textureId)
|
if (m_textureId)
|
||||||
{
|
{
|
||||||
glDeleteTextures(1, &m_textureId);
|
glDeleteTextures(1, &m_textureId);
|
||||||
m_textureId = 0;
|
m_textureId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &m_textureId);
|
glGenTextures(1, &m_textureId);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
|
||||||
image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.constScanLine(0));
|
image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.constScanLine(0));
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
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_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::subTexture(int xOffset, int yOffset, int width, int height, const void *pixels)
|
void GLShaderTextured::subTexture(int xOffset, int yOffset, int width, int height, const void *pixels)
|
||||||
@ -152,33 +152,33 @@ void GLShaderTextured::subTexture(int xOffset, int yOffset, int width, int heigh
|
|||||||
|
|
||||||
void GLShaderTextured::subTextureImmutable(int xOffset, int yOffset, int width, int height, const void *pixels)
|
void GLShaderTextured::subTextureImmutable(int xOffset, int yOffset, int width, int height, const void *pixels)
|
||||||
{
|
{
|
||||||
if (!m_texture)
|
if (!m_texture)
|
||||||
{
|
{
|
||||||
qDebug("GLShaderTextured::subTextureImmutable: no texture defined. Doing nothing");
|
qDebug("GLShaderTextured::subTextureImmutable: no texture defined. Doing nothing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
m_texture->bind();
|
m_texture->bind();
|
||||||
f->glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
f->glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::subTextureMutable(int xOffset, int yOffset, int width, int height, const void *pixels)
|
void GLShaderTextured::subTextureMutable(int xOffset, int yOffset, int width, int height, const void *pixels)
|
||||||
{
|
{
|
||||||
if (!m_textureId)
|
if (!m_textureId)
|
||||||
{
|
{
|
||||||
qDebug("GLShaderTextured::subTextureMutable: no texture defined. Doing nothing");
|
qDebug("GLShaderTextured::subTextureMutable: no texture defined. Doing nothing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::drawSurface(const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderTextured::drawSurface(const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
if (m_useImmutableStorage) {
|
if (m_useImmutableStorage) {
|
||||||
draw(GL_TRIANGLE_FAN, transformMatrix, textureCoords, vertices, nbVertices, nbComponents);
|
draw(GL_TRIANGLE_FAN, transformMatrix, textureCoords, vertices, nbVertices, nbComponents);
|
||||||
} else {
|
} else {
|
||||||
drawMutable(GL_TRIANGLE_FAN, transformMatrix, textureCoords, vertices, nbVertices, nbComponents);
|
drawMutable(GL_TRIANGLE_FAN, transformMatrix, textureCoords, vertices, nbVertices, nbComponents);
|
||||||
}
|
}
|
||||||
@ -186,17 +186,17 @@ void GLShaderTextured::drawSurface(const QMatrix4x4& transformMatrix, GLfloat *t
|
|||||||
|
|
||||||
void GLShaderTextured::draw(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderTextured::draw(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
if (!m_texture)
|
if (!m_texture)
|
||||||
{
|
{
|
||||||
qDebug("GLShaderTextured::draw: no texture defined. Doing nothing");
|
qDebug("GLShaderTextured::draw: no texture defined. Doing nothing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
m_program->setUniformValue(m_matrixLoc, transformMatrix);
|
m_program->setUniformValue(m_matrixLoc, transformMatrix);
|
||||||
m_texture->bind();
|
m_texture->bind();
|
||||||
m_program->setUniformValue(m_textureLoc, 0); // Use texture unit 0 which magically contains our texture
|
m_program->setUniformValue(m_textureLoc, 0); // Use texture unit 0 which magically contains our texture
|
||||||
if (m_vao)
|
if (m_vao)
|
||||||
{
|
{
|
||||||
m_vao->bind();
|
m_vao->bind();
|
||||||
@ -213,13 +213,13 @@ void GLShaderTextured::draw(unsigned int mode, const QMatrix4x4& transformMatrix
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f->glEnableVertexAttribArray(m_vertexLoc); // vertex
|
f->glEnableVertexAttribArray(m_vertexLoc); // vertex
|
||||||
f->glVertexAttribPointer(m_vertexLoc, nbComponents, GL_FLOAT, GL_FALSE, 0, vertices);
|
f->glVertexAttribPointer(m_vertexLoc, nbComponents, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||||
f->glEnableVertexAttribArray(m_texCoordLoc); // texture coordinates
|
f->glEnableVertexAttribArray(m_texCoordLoc); // texture coordinates
|
||||||
f->glVertexAttribPointer(m_texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
|
f->glVertexAttribPointer(m_texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
f->glDrawArrays(mode, 0, nbVertices);
|
f->glDrawArrays(mode, 0, nbVertices);
|
||||||
|
|
||||||
if (m_vao)
|
if (m_vao)
|
||||||
{
|
{
|
||||||
@ -227,32 +227,32 @@ void GLShaderTextured::draw(unsigned int mode, const QMatrix4x4& transformMatrix
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
f->glDisableVertexAttribArray(m_vertexLoc);
|
f->glDisableVertexAttribArray(m_vertexLoc);
|
||||||
f->glDisableVertexAttribArray(m_texCoordLoc);
|
f->glDisableVertexAttribArray(m_texCoordLoc);
|
||||||
}
|
}
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::drawMutable(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents)
|
void GLShaderTextured::drawMutable(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents)
|
||||||
{
|
{
|
||||||
if (!m_textureId)
|
if (!m_textureId)
|
||||||
{
|
{
|
||||||
qDebug("GLShaderTextured::drawMutable: no texture defined. Doing nothing");
|
qDebug("GLShaderTextured::drawMutable: no texture defined. Doing nothing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_program->bind();
|
m_program->bind();
|
||||||
m_program->setUniformValue(m_matrixLoc, transformMatrix);
|
m_program->setUniformValue(m_matrixLoc, transformMatrix);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
glBindTexture(GL_TEXTURE_2D, m_textureId);
|
||||||
m_program->setUniformValue(m_textureLoc, 0); // Use texture unit 0 which magically contains our texture
|
m_program->setUniformValue(m_textureLoc, 0); // Use texture unit 0 which magically contains our texture
|
||||||
glEnableVertexAttribArray(m_vertexLoc); // vertex
|
glEnableVertexAttribArray(m_vertexLoc); // vertex
|
||||||
glVertexAttribPointer(m_vertexLoc, nbComponents, GL_FLOAT, GL_FALSE, 0, vertices);
|
glVertexAttribPointer(m_vertexLoc, nbComponents, GL_FLOAT, GL_FALSE, 0, vertices);
|
||||||
glEnableVertexAttribArray(m_texCoordLoc); // texture coordinates
|
glEnableVertexAttribArray(m_texCoordLoc); // texture coordinates
|
||||||
glVertexAttribPointer(m_texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
|
glVertexAttribPointer(m_texCoordLoc, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
|
||||||
glDrawArrays(mode, 0, nbVertices);
|
glDrawArrays(mode, 0, nbVertices);
|
||||||
glDisableVertexAttribArray(m_vertexLoc);
|
glDisableVertexAttribArray(m_vertexLoc);
|
||||||
glDisableVertexAttribArray(m_texCoordLoc);
|
glDisableVertexAttribArray(m_texCoordLoc);
|
||||||
m_program->release();
|
m_program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLShaderTextured::cleanup()
|
void GLShaderTextured::cleanup()
|
||||||
@ -268,9 +268,9 @@ void GLShaderTextured::cleanup()
|
|||||||
delete m_texture;
|
delete m_texture;
|
||||||
m_texture = nullptr;
|
m_texture = nullptr;
|
||||||
|
|
||||||
if (!QOpenGLContext::currentContext()) {
|
if (!QOpenGLContext::currentContext()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_textureId)
|
if (m_textureId)
|
||||||
{
|
{
|
||||||
@ -307,42 +307,42 @@ bool GLShaderTextured::useImmutableStorage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QString GLShaderTextured::m_vertexShaderSourceTextured2 = QString(
|
const QString GLShaderTextured::m_vertexShaderSourceTextured2 = QString(
|
||||||
"uniform highp mat4 uMatrix;\n"
|
"uniform highp mat4 uMatrix;\n"
|
||||||
"attribute highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"attribute highp vec2 texCoord;\n"
|
"attribute highp vec2 texCoord;\n"
|
||||||
"varying mediump vec2 texCoordVar;\n"
|
"varying mediump vec2 texCoordVar;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = uMatrix * vertex;\n"
|
" gl_Position = uMatrix * vertex;\n"
|
||||||
" texCoordVar = texCoord;\n"
|
" texCoordVar = texCoord;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderTextured::m_vertexShaderSourceTextured = QString(
|
const QString GLShaderTextured::m_vertexShaderSourceTextured = QString(
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
"uniform highp mat4 uMatrix;\n"
|
"uniform highp mat4 uMatrix;\n"
|
||||||
"in highp vec4 vertex;\n"
|
"in highp vec4 vertex;\n"
|
||||||
"in highp vec2 texCoord;\n"
|
"in highp vec2 texCoord;\n"
|
||||||
"out mediump vec2 texCoordVar;\n"
|
"out mediump vec2 texCoordVar;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = uMatrix * vertex;\n"
|
" gl_Position = uMatrix * vertex;\n"
|
||||||
" texCoordVar = texCoord;\n"
|
" texCoordVar = texCoord;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderTextured::m_fragmentShaderSourceTextured2 = QString(
|
const QString GLShaderTextured::m_fragmentShaderSourceTextured2 = QString(
|
||||||
"uniform lowp sampler2D uTexture;\n"
|
"uniform lowp sampler2D uTexture;\n"
|
||||||
"varying mediump vec2 texCoordVar;\n"
|
"varying mediump vec2 texCoordVar;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_FragColor = texture2D(uTexture, texCoordVar);\n"
|
" gl_FragColor = texture2D(uTexture, texCoordVar);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
const QString GLShaderTextured::m_fragmentShaderSourceTextured = QString(
|
const QString GLShaderTextured::m_fragmentShaderSourceTextured = QString(
|
||||||
"#version 330\n"
|
"#version 330\n"
|
||||||
"uniform lowp sampler2D uTexture;\n"
|
"uniform lowp sampler2D uTexture;\n"
|
||||||
"in mediump vec2 texCoordVar;\n"
|
"in mediump vec2 texCoordVar;\n"
|
||||||
"out vec4 fragColor;\n"
|
"out vec4 fragColor;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" fragColor = texture(uTexture, texCoordVar);\n"
|
" fragColor = texture(uTexture, texCoordVar);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
);
|
);
|
||||||
|
@ -37,39 +37,39 @@ class QImage;
|
|||||||
class SDRGUI_API GLShaderTextured : protected QOpenGLFunctions
|
class SDRGUI_API GLShaderTextured : protected QOpenGLFunctions
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GLShaderTextured();
|
GLShaderTextured();
|
||||||
~GLShaderTextured();
|
~GLShaderTextured();
|
||||||
|
|
||||||
void initializeGL(int majorVersion, int minorVersion);
|
void initializeGL(int majorVersion, int minorVersion);
|
||||||
void initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
void initTexture(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
||||||
void subTexture(int xOffset, int yOffset, int width, int height, const void *pixels);
|
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);
|
void drawSurface(const QMatrix4x4& transformMatrix, GLfloat* textureCoords, GLfloat *vertices, int nbVertices, int nbComponents=2);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void draw(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents);
|
void draw(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents);
|
||||||
void drawMutable(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents);
|
void drawMutable(unsigned int mode, const QMatrix4x4& transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices, int nbComponents);
|
||||||
void initTextureImmutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
void initTextureImmutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
||||||
void subTextureImmutable(int xOffset, int yOffset, int width, int height, const void *pixels);
|
void subTextureImmutable(int xOffset, int yOffset, int width, int height, const void *pixels);
|
||||||
void initTextureMutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
void initTextureMutable(const QImage& image, QOpenGLTexture::WrapMode wrapMode = QOpenGLTexture::Repeat);
|
||||||
void subTextureMutable(int xOffset, int yOffset, int width, int height, const void *pixels);
|
void subTextureMutable(int xOffset, int yOffset, int width, int height, const void *pixels);
|
||||||
bool useImmutableStorage();
|
bool useImmutableStorage();
|
||||||
|
|
||||||
QOpenGLShaderProgram *m_program;
|
QOpenGLShaderProgram *m_program;
|
||||||
QOpenGLVertexArrayObject *m_vao;
|
QOpenGLVertexArrayObject *m_vao;
|
||||||
QOpenGLBuffer *m_verticesBuf;
|
QOpenGLBuffer *m_verticesBuf;
|
||||||
QOpenGLBuffer *m_textureCoordsBuf;
|
QOpenGLBuffer *m_textureCoordsBuf;
|
||||||
QOpenGLTexture *m_texture;
|
QOpenGLTexture *m_texture;
|
||||||
unsigned int m_textureId;
|
unsigned int m_textureId;
|
||||||
int m_vertexLoc;
|
int m_vertexLoc;
|
||||||
int m_texCoordLoc;
|
int m_texCoordLoc;
|
||||||
int m_matrixLoc;
|
int m_matrixLoc;
|
||||||
int m_textureLoc;
|
int m_textureLoc;
|
||||||
bool m_useImmutableStorage;
|
bool m_useImmutableStorage;
|
||||||
static const QString m_vertexShaderSourceTextured2;
|
static const QString m_vertexShaderSourceTextured2;
|
||||||
static const QString m_vertexShaderSourceTextured;
|
static const QString m_vertexShaderSourceTextured;
|
||||||
static const QString m_fragmentShaderSourceTextured2;
|
static const QString m_fragmentShaderSourceTextured2;
|
||||||
static const QString m_fragmentShaderSourceTextured;
|
static const QString m_fragmentShaderSourceTextured;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* INCLUDE_GUI_GLSHADERTEXTURED_H_ */
|
#endif /* INCLUDE_GUI_GLSHADERTEXTURED_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user