2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef SHADERINTERFACE_H
|
|
|
|
#define SHADERINTERFACE_H
|
|
|
|
|
|
|
|
// Glew includes
|
2016-06-15 18:43:10 +12:00
|
|
|
#include <GL/glew.h> // Must be included before tgl.h
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// TnzBase includes
|
|
|
|
#include "tparamuiconcept.h"
|
|
|
|
|
|
|
|
// TnzCore includes
|
|
|
|
#include "tpersist.h"
|
|
|
|
#include "tfilepath.h"
|
|
|
|
#include "tgl.h"
|
|
|
|
|
|
|
|
// Qt includes
|
|
|
|
#include <QString>
|
|
|
|
#include <QDateTime>
|
2017-07-01 16:51:18 +12:00
|
|
|
#include <QOpenGLShader>
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
// STD includes
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
#ifdef TNZSTDFX_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
|
2017-07-01 16:51:18 +12:00
|
|
|
class QOpenGLShaderProgram;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//=========================================================
|
|
|
|
|
|
|
|
//**********************************************************************
|
|
|
|
// ShaderInterface declaration
|
|
|
|
//**********************************************************************
|
|
|
|
|
|
|
|
/*!
|
|
|
|
A ShaderInterface represents interface data to a GLSL shader program.
|
|
|
|
|
|
|
|
\par Rationale
|
|
|
|
|
|
|
|
OpenGL shaders are supplied as text to be compiled at run-time by a
|
|
|
|
GLSL compiler. In our case, the specified text is assumed to be stored in
|
|
|
|
one or more files on hard-disk.
|
|
|
|
\n\n
|
|
|
|
However, in order for an executable to correctly interface a GLSL
|
|
|
|
shader program, further interface data must be supplied in some form.
|
|
|
|
|
|
|
|
Interface data include the path of the GLSL shader program file and
|
|
|
|
parameters to be bound by the executable before the shader is run.
|
|
|
|
|
|
|
|
\par Usage
|
|
|
|
|
|
|
|
A ShaderInterface is loaded from an xml file. Since an interface could
|
|
|
|
be loaded incorrectly, remember to check the isValid() method to ensure
|
|
|
|
that the loading process succeeds.
|
|
|
|
|
|
|
|
A loaded ShaderInterface allows access to shader parameters and
|
|
|
|
acts as a factory object to compiled QGLShaderProgram instances.
|
|
|
|
*/
|
2016-06-29 18:17:12 +12:00
|
|
|
class DVAPI ShaderInterface final : public TPersist {
|
2016-06-15 18:43:10 +12:00
|
|
|
public: // Enums
|
|
|
|
enum ParameterConceptType {
|
|
|
|
CONCEPT_NONE,
|
|
|
|
PERCENT,
|
|
|
|
LENGTH,
|
|
|
|
ANGLE,
|
|
|
|
POINT,
|
|
|
|
RADIUS_UI,
|
|
|
|
WIDTH_UI,
|
|
|
|
ANGLE_UI,
|
|
|
|
POINT_UI,
|
|
|
|
XY_UI,
|
|
|
|
VECTOR_UI,
|
|
|
|
POLAR_UI,
|
|
|
|
SIZE_UI,
|
|
|
|
QUAD_UI,
|
|
|
|
RECT_UI,
|
|
|
|
|
|
|
|
CONCEPTSCOUNT,
|
|
|
|
UI_CONCEPTS = RADIUS_UI
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ParameterType {
|
|
|
|
PARAMETER_UNKNOWN,
|
|
|
|
BOOL,
|
|
|
|
FLOAT,
|
|
|
|
VEC2,
|
|
|
|
VEC3,
|
|
|
|
VEC4,
|
|
|
|
INT,
|
|
|
|
IVEC2,
|
|
|
|
IVEC3,
|
|
|
|
IVEC4,
|
|
|
|
RGBA,
|
|
|
|
RGB,
|
|
|
|
TYPESCOUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum HandledWorldTransformsType { HWT_UNKNOWN, ANY, ISOTROPIC, HWTCOUNT };
|
|
|
|
|
|
|
|
public: // Sub-classes
|
2016-06-29 18:17:12 +12:00
|
|
|
class ParameterConcept final : public TPersist {
|
2016-06-15 18:43:10 +12:00
|
|
|
PERSIST_DECLARATION(ParameterConcept)
|
|
|
|
|
|
|
|
public:
|
|
|
|
ParameterConceptType m_type; //!< The concept type (typically composite)
|
|
|
|
QString m_label; //!< Name to be shown for ui concepts
|
|
|
|
std::vector<QString>
|
|
|
|
m_parameterNames; //!< The involved parameters (by name)
|
|
|
|
|
|
|
|
public:
|
|
|
|
ParameterConcept() : m_type(CONCEPT_NONE) {}
|
|
|
|
ParameterConcept(ParameterConceptType type, const QString &label)
|
|
|
|
: m_type(type), m_label(label) {}
|
|
|
|
|
|
|
|
bool isUI() const {
|
|
|
|
return m_type >= UI_CONCEPTS && m_type < CONCEPTSCOUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2016-06-19 20:06:29 +12:00
|
|
|
void saveData(TOStream &os) override;
|
|
|
|
void loadData(TIStream &is) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
};
|
|
|
|
|
|
|
|
union ParameterValue {
|
|
|
|
GLboolean m_bool;
|
|
|
|
GLfloat m_float;
|
|
|
|
GLfloat m_vec2[2];
|
|
|
|
GLfloat m_vec3[3];
|
|
|
|
GLfloat m_vec4[4];
|
|
|
|
GLint m_int;
|
|
|
|
GLint m_ivec2[2];
|
|
|
|
GLint m_ivec3[3];
|
|
|
|
GLint m_ivec4[4];
|
|
|
|
GLubyte m_rgba[4];
|
|
|
|
GLubyte m_rgb[3];
|
|
|
|
};
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class Parameter final : public TPersist {
|
2016-06-15 18:43:10 +12:00
|
|
|
PERSIST_DECLARATION(Parameter)
|
|
|
|
|
|
|
|
public:
|
|
|
|
ParameterType m_type;
|
|
|
|
QString m_name;
|
|
|
|
|
|
|
|
ParameterValue m_default;
|
|
|
|
ParameterValue m_range[2];
|
|
|
|
|
|
|
|
ParameterConcept m_concept;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Parameter() : m_type(PARAMETER_UNKNOWN) {}
|
|
|
|
Parameter(ParameterType type, const QString &name)
|
|
|
|
: m_type(type), m_name(name) {}
|
|
|
|
|
|
|
|
protected:
|
2016-06-19 20:06:29 +12:00
|
|
|
void saveData(TOStream &os) override;
|
|
|
|
void loadData(TIStream &is) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
};
|
|
|
|
|
2016-06-29 18:17:12 +12:00
|
|
|
class ShaderData final : public TPersist {
|
2016-06-15 18:43:10 +12:00
|
|
|
PERSIST_DECLARATION(ShaderData)
|
|
|
|
|
|
|
|
public:
|
2017-10-11 15:40:34 +13:00
|
|
|
QString m_name; //!< A name associated to the shader action
|
|
|
|
TFilePath m_path; //!< The shader program's file path
|
2017-07-01 16:51:18 +12:00
|
|
|
QOpenGLShader::ShaderType m_type; //!< The shader type
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool isValid() const { return !m_path.isEmpty(); }
|
|
|
|
|
|
|
|
protected:
|
2016-06-19 20:06:29 +12:00
|
|
|
void saveData(TOStream &os) override;
|
|
|
|
void loadData(TIStream &is) override;
|
2016-06-15 18:43:10 +12:00
|
|
|
};
|
|
|
|
|
|
|
|
public: // Public methods
|
|
|
|
ShaderInterface();
|
|
|
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
|
|
|
const std::vector<Parameter> ¶meters() const;
|
|
|
|
const std::vector<QString> &inputPorts() const;
|
|
|
|
|
|
|
|
const ShaderData &mainShader() const;
|
|
|
|
const ShaderData &inputPortsShader() const;
|
|
|
|
const ShaderData &bboxShader() const;
|
|
|
|
|
|
|
|
HandledWorldTransformsType hwtType() const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Returns a compiled shader program against current OpenGL context, and the
|
|
|
|
last modified date of the associated shader file.
|
|
|
|
*/
|
2017-07-01 16:51:18 +12:00
|
|
|
std::pair<QOpenGLShaderProgram *, QDateTime> makeProgram(
|
2016-06-15 18:43:10 +12:00
|
|
|
const ShaderData &sd, int varyingsCount = 0,
|
|
|
|
const GLchar **varyingNames = 0) const;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected:
|
2016-06-15 18:43:10 +12:00
|
|
|
void clear();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-19 20:06:29 +12:00
|
|
|
void saveData(TOStream &os) override;
|
|
|
|
void loadData(TIStream &is) override;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
private:
|
2016-06-15 18:43:10 +12:00
|
|
|
PERSIST_DECLARATION(ShaderInterface)
|
|
|
|
|
|
|
|
ShaderData m_mainShader; //!< Main (fragment) shader data
|
|
|
|
std::vector<Parameter> m_parameters; //!< List of parameters for the shader
|
|
|
|
std::vector<ParameterConcept>
|
|
|
|
m_parConcepts; //!< List of (composite) parameter concepts
|
|
|
|
|
|
|
|
std::vector<QString> m_ports;
|
|
|
|
ShaderData m_portsShader; //!< (Vertex) shader dedicated to input
|
|
|
|
//!< ports' geometries calculation
|
|
|
|
ShaderData m_bboxShader; //!< (Vertex) shader dedicated to extracting
|
|
|
|
//!< the fx's bbox
|
|
|
|
HandledWorldTransformsType m_hwt; //!< World transform types \a handled by
|
|
|
|
//!< associated ShaderFx instances
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // SHADERINTERFACE_H
|