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
GLShaderSimple Class Reference

#include <glshadersimple.h>

Public Member Functions

 GLShaderSimple ()
 
 ~GLShaderSimple ()
 
void initializeGL ()
 
void drawPoints (const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
 
void drawPolyline (const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
 
void drawSegments (const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
 
void drawContour (const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
 
void drawSurface (const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
 
void cleanup ()
 

Private Member Functions

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

Private Attributes

QOpenGLShaderProgram * m_program
 
int m_matrixLoc
 
int m_colorLoc
 

Static Private Attributes

static const QString m_vertexShaderSourceSimple
 
static const QString m_fragmentShaderSourceColored
 

Detailed Description

Definition at line 31 of file glshadersimple.h.

Constructor & Destructor Documentation

◆ GLShaderSimple()

GLShaderSimple::GLShaderSimple ( )

Definition at line 28 of file glshadersimple.cpp.

28  :
29  m_program(0),
30  m_matrixLoc(0),
31  m_colorLoc(0)
32 { }
QOpenGLShaderProgram * m_program

◆ ~GLShaderSimple()

GLShaderSimple::~GLShaderSimple ( )

Definition at line 34 of file glshadersimple.cpp.

References cleanup().

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

Member Function Documentation

◆ cleanup()

void GLShaderSimple::cleanup ( )

Definition at line 104 of file glshadersimple.cpp.

References m_fragmentShaderSourceColored, m_program, and m_vertexShaderSourceSimple.

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

105 {
106  if (m_program)
107  {
108  delete m_program;
109  m_program = 0;
110  }
111 }
QOpenGLShaderProgram * m_program
+ Here is the caller graph for this function:

◆ draw()

void GLShaderSimple::draw ( unsigned int  mode,
const QMatrix4x4 &  transformMatrix,
const QVector4D &  color,
GLfloat *  vertices,
int  nbVertices 
)
private

Definition at line 88 of file glshadersimple.cpp.

References m_colorLoc, m_matrixLoc, and m_program.

Referenced by drawContour(), drawPoints(), drawPolyline(), drawSegments(), and drawSurface().

89 {
90  QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
91  m_program->bind();
92  m_program->setUniformValue(m_matrixLoc, transformMatrix);
93  m_program->setUniformValue(m_colorLoc, color);
94  f->glEnable(GL_BLEND);
95  f->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
96  f->glLineWidth(1.0f);
97  f->glEnableVertexAttribArray(0); // vertex
98  f->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, vertices);
99  f->glDrawArrays(mode, 0, nbVertices);
100  f->glDisableVertexAttribArray(0);
101  m_program->release();
102 }
QOpenGLShaderProgram * m_program
+ Here is the caller graph for this function:

◆ drawContour()

void GLShaderSimple::drawContour ( const QMatrix4x4 &  transformMatrix,
const QVector4D &  color,
GLfloat *  vertices,
int  nbVertices 
)

Definition at line 78 of file glshadersimple.cpp.

References draw().

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

79 {
80  draw(GL_LINE_LOOP, transformMatrix, color, vertices, nbVertices);
81 }
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawPoints()

void GLShaderSimple::drawPoints ( const QMatrix4x4 &  transformMatrix,
const QVector4D &  color,
GLfloat *  vertices,
int  nbVertices 
)

Definition at line 63 of file glshadersimple.cpp.

References draw().

Referenced by GLScope::paintGL().

64 {
65  draw(GL_POINTS, transformMatrix, color, vertices, nbVertices);
66 }
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawPolyline()

void GLShaderSimple::drawPolyline ( const QMatrix4x4 &  transformMatrix,
const QVector4D &  color,
GLfloat *  vertices,
int  nbVertices 
)

Definition at line 68 of file glshadersimple.cpp.

References draw().

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

69 {
70  draw(GL_LINE_STRIP, transformMatrix, color, vertices, nbVertices);
71 }
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawSegments()

void GLShaderSimple::drawSegments ( const QMatrix4x4 &  transformMatrix,
const QVector4D &  color,
GLfloat *  vertices,
int  nbVertices 
)

Definition at line 73 of file glshadersimple.cpp.

References draw().

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

74 {
75  draw(GL_LINES, transformMatrix, color, vertices, nbVertices);
76 }
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ drawSurface()

void GLShaderSimple::drawSurface ( const QMatrix4x4 &  transformMatrix,
const QVector4D &  color,
GLfloat *  vertices,
int  nbVertices 
)

Definition at line 83 of file glshadersimple.cpp.

References draw().

Referenced by GLSpectrum::paintGL().

84 {
85  draw(GL_TRIANGLE_FAN, transformMatrix, color, vertices, nbVertices);
86 }
void draw(unsigned int mode, const QMatrix4x4 &transformMatrix, const QVector4D &color, GLfloat *vertices, int nbVertices)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initializeGL()

void GLShaderSimple::initializeGL ( )

Definition at line 39 of file glshadersimple.cpp.

References m_colorLoc, m_fragmentShaderSourceColored, m_matrixLoc, m_program, and m_vertexShaderSourceSimple.

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

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

Member Data Documentation

◆ m_colorLoc

int GLShaderSimple::m_colorLoc
private

Definition at line 50 of file glshadersimple.h.

Referenced by draw(), and initializeGL().

◆ m_fragmentShaderSourceColored

const QString GLShaderSimple::m_fragmentShaderSourceColored
staticprivate
Initial value:
= QString(
"uniform mediump vec4 uColour;\n"
"void main() {\n"
" gl_FragColor = uColour;\n"
"}\n"
)

Definition at line 52 of file glshadersimple.h.

Referenced by cleanup(), and initializeGL().

◆ m_matrixLoc

int GLShaderSimple::m_matrixLoc
private

Definition at line 49 of file glshadersimple.h.

Referenced by draw(), and initializeGL().

◆ m_program

QOpenGLShaderProgram* GLShaderSimple::m_program
private

Definition at line 48 of file glshadersimple.h.

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

◆ m_vertexShaderSourceSimple

const QString GLShaderSimple::m_vertexShaderSourceSimple
staticprivate
Initial value:
= QString(
"uniform highp mat4 uMatrix;\n"
"attribute highp vec4 vertex;\n"
"void main() {\n"
" gl_Position = uMatrix * vertex;\n"
"}\n"
)

Definition at line 51 of file glshadersimple.h.

Referenced by cleanup(), and initializeGL().


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