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