SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
GLShaderTextured Class Reference

#include <glshadertextured.h>

Public Member Functions

 GLShaderTextured ()
 
 ~GLShaderTextured ()
 
void initializeGL ()
 
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)
 
void cleanup ()
 

Private Member Functions

void draw (unsigned int mode, const QMatrix4x4 &transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices)
 

Private Attributes

QOpenGLShaderProgram * m_program
 
QOpenGLTexture * m_texture
 
int m_matrixLoc
 
int m_textureLoc
 

Static Private Attributes

static const QString m_vertexShaderSourceTextured
 
static const QString m_fragmentShaderSourceTextured
 

Detailed Description

Definition at line 35 of file glshadertextured.h.

Constructor & Destructor Documentation

◆ GLShaderTextured()

GLShaderTextured::GLShaderTextured ( )

Definition at line 29 of file glshadertextured.cpp.

29  :
30  m_program(0),
31  m_texture(0),
32  m_matrixLoc(0),
33  m_textureLoc(0)
34 { }
QOpenGLShaderProgram * m_program
QOpenGLTexture * m_texture

◆ ~GLShaderTextured()

GLShaderTextured::~GLShaderTextured ( )

Definition at line 36 of file glshadertextured.cpp.

References cleanup().

37 {
38  cleanup();
39 }
+ Here is the call graph for this function:

Member Function Documentation

◆ cleanup()

void GLShaderTextured::cleanup ( )

Definition at line 117 of file glshadertextured.cpp.

References m_fragmentShaderSourceTextured, m_program, m_texture, and m_vertexShaderSourceTextured.

Referenced by GLScope::cleanup(), GLSpectrum::cleanup(), and ~GLShaderTextured().

118 {
119  if (m_program) {
120  delete m_program;
121  m_program = 0;
122  }
123 
124  if (m_texture) {
125  delete m_texture;
126  m_texture = 0;
127  }
128 }
QOpenGLShaderProgram * m_program
QOpenGLTexture * m_texture
+ Here is the caller graph for this function:

◆ draw()

void GLShaderTextured::draw ( unsigned int  mode,
const QMatrix4x4 &  transformMatrix,
GLfloat *  textureCoords,
GLfloat *  vertices,
int  nbVertices 
)
private

Definition at line 96 of file glshadertextured.cpp.

References m_matrixLoc, m_program, m_texture, and m_textureLoc.

Referenced by drawSurface().

97 {
98  if (!m_texture) {
99  qDebug("GLShaderTextured::draw: no texture defined. Doing nothing");
100  return;
101  }
102 
103  QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
104  m_program->bind();
105  m_program->setUniformValue(m_matrixLoc, transformMatrix);
106  m_texture->bind();
107  m_program->setUniformValue(m_textureLoc, 0); // Use texture unit 0 which magically contains our texture
108  f->glEnableVertexAttribArray(0); // vertex
109  f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
110  f->glEnableVertexAttribArray(1); // texture coordinates
111  f->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureCoords);
112  f->glDrawArrays(mode, 0, nbVertices);
113  f->glDisableVertexAttribArray(0);
114  m_program->release();
115 }
QOpenGLShaderProgram * m_program
QOpenGLTexture * m_texture
+ Here is the caller graph for this function:

◆ drawSurface()

void GLShaderTextured::drawSurface ( const QMatrix4x4 &  transformMatrix,
GLfloat *  textureCoords,
GLfloat *  vertices,
int  nbVertices 
)

Definition at line 91 of file glshadertextured.cpp.

References draw().

Referenced by GLScope::drawChannelOverlay(), GLScope::paintGL(), and GLSpectrum::paintGL().

92 {
93  draw(GL_TRIANGLE_FAN, transformMatrix, textureCoords, vertices, nbVertices);
94 }
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, GLfloat *textureCoords, GLfloat *vertices, int nbVertices)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initializeGL()

void GLShaderTextured::initializeGL ( )

Definition at line 41 of file glshadertextured.cpp.

References m_fragmentShaderSourceTextured, m_matrixLoc, m_program, m_textureLoc, and m_vertexShaderSourceTextured.

Referenced by GLScope::initializeGL(), and GLSpectrum::initializeGL().

42 {
43  m_program = new QOpenGLShaderProgram;
44 
45  if (!m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, m_vertexShaderSourceTextured)) {
46  qDebug() << "GLShaderTextured::initializeGL: error in vertex shader: " << m_program->log();
47  }
48 
49  if (!m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, m_fragmentShaderSourceTextured)) {
50  qDebug() << "GLShaderTextured::initializeGL: error in fragment shader: " << m_program->log();
51  }
52 
53  m_program->bindAttributeLocation("vertex", 0);
54  m_program->bindAttributeLocation("texCoord", 1);
55 
56  if (!m_program->link()) {
57  qDebug() << "GLShaderTextured::initializeGL: error linking shader: " << m_program->log();
58  }
59 
60  m_program->bind();
61  m_matrixLoc = m_program->uniformLocation("uMatrix");
62  m_textureLoc = m_program->uniformLocation("uTexture");
63  m_program->release();
64 }
QOpenGLShaderProgram * m_program
static const QString m_vertexShaderSourceTextured
static const QString m_fragmentShaderSourceTextured
+ Here is the caller graph for this function:

◆ initTexture()

void GLShaderTextured::initTexture ( const QImage &  image,
QOpenGLTexture::WrapMode  wrapMode = QOpenGLTexture::Repeat 
)

Definition at line 66 of file glshadertextured.cpp.

References m_texture.

Referenced by GLSpectrum::applyChanges(), GLScope::drawChannelOverlay(), GLScope::setHorizontalDisplays(), GLScope::setPolarDisplays(), GLScope::setUniqueDisplays(), and GLScope::setVerticalDisplays().

67 {
68  if (m_texture) {
69  delete m_texture;
70  }
71 
72  m_texture = new QOpenGLTexture(image);
73 
74  m_texture->setMinificationFilter(QOpenGLTexture::Linear);
75  m_texture->setMagnificationFilter(QOpenGLTexture::Linear);
76  m_texture->setWrapMode(wrapMode);
77 }
QOpenGLTexture * m_texture
+ Here is the caller graph for this function:

◆ subTexture()

void GLShaderTextured::subTexture ( int  xOffset,
int  yOffset,
int  width,
int  height,
const void *  pixels 
)

Definition at line 79 of file glshadertextured.cpp.

References m_texture.

Referenced by GLSpectrum::paintGL().

80 {
81  if (!m_texture) {
82  qDebug("GLShaderTextured::subTexture: no texture defined. Doing nothing");
83  return;
84  }
85 
86  QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
87  m_texture->bind();
88  f->glTexSubImage2D(GL_TEXTURE_2D, 0, xOffset, yOffset, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
89 }
QOpenGLTexture * m_texture
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_fragmentShaderSourceTextured

const QString GLShaderTextured::m_fragmentShaderSourceTextured
staticprivate
Initial value:
= QString(
"uniform lowp sampler2D uTexture;\n"
"varying mediump vec2 texCoordVar;\n"
"void main() {\n"
" gl_FragColor = texture2D(uTexture, texCoordVar);\n"
"}\n"
)

Definition at line 55 of file glshadertextured.h.

Referenced by cleanup(), and initializeGL().

◆ m_matrixLoc

int GLShaderTextured::m_matrixLoc
private

Definition at line 52 of file glshadertextured.h.

Referenced by draw(), and initializeGL().

◆ m_program

QOpenGLShaderProgram* GLShaderTextured::m_program
private

Definition at line 50 of file glshadertextured.h.

Referenced by cleanup(), draw(), and initializeGL().

◆ m_texture

QOpenGLTexture* GLShaderTextured::m_texture
private

Definition at line 51 of file glshadertextured.h.

Referenced by cleanup(), draw(), initTexture(), and subTexture().

◆ m_textureLoc

int GLShaderTextured::m_textureLoc
private

Definition at line 53 of file glshadertextured.h.

Referenced by draw(), and initializeGL().

◆ m_vertexShaderSourceTextured

const QString GLShaderTextured::m_vertexShaderSourceTextured
staticprivate
Initial value:
= QString(
"uniform highp mat4 uMatrix;\n"
"attribute highp vec4 vertex;\n"
"attribute highp vec2 texCoord;\n"
"varying mediump vec2 texCoordVar;\n"
"void main() {\n"
" gl_Position = uMatrix * vertex;\n"
" texCoordVar = texCoord;\n"
"}\n"
)

Definition at line 54 of file glshadertextured.h.

Referenced by cleanup(), and initializeGL().


The documentation for this class was generated from the following files: