tahoma2d/toonz/sources/include/stdfx/shadingcontext.h

111 lines
2.9 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef SHADINGCONTEXT_H
#define SHADINGCONTEXT_H
2016-04-14 22:15:09 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
// Glew include
#include <GL/glew.h>
// TnzCore includes
#include "traster.h"
// Qt includes
#include <QDateTime>
2017-07-01 16:51:18 +12:00
#include <QOpenGLFramebufferObjectFormat>
#include <QOpenGLWidget>
2016-03-19 06:57:51 +13:00
#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
class QObject;
2017-07-01 16:51:18 +12:00
class QOpenGLShaderProgram;
2016-03-19 06:57:51 +13:00
class QDateTime;
2017-07-01 16:51:18 +12:00
class QOffScreenSurface;
2016-03-19 06:57:51 +13:00
//=========================================================
2016-06-15 18:43:10 +12:00
class DVAPI ShadingContext {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
enum Support { OK, NO_PIXEL_BUFFER, NO_SHADERS };
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
ShadingContext();
~ShadingContext();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Returns the status of OpenGL shading support.
static Support support();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool isValid() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void makeCurrent();
void doneCurrent();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
/*!
Resizes the output buffer to the specified size. Requires that
the contex is made current before invocation. In case lx or ly are 0,
the context's output buffer is destroyed.
*/
2017-07-01 16:51:18 +12:00
void resize(int lx, int ly, const QOpenGLFramebufferObjectFormat &fmt =
QOpenGLFramebufferObjectFormat());
2016-03-19 06:57:51 +13:00
2017-07-01 16:51:18 +12:00
QOpenGLFramebufferObjectFormat format() const;
2016-06-15 18:43:10 +12:00
TDimension size() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Surrenders ownership of the supplied shader program to the shading
//! context.
2017-07-01 16:51:18 +12:00
void addShaderProgram(const QString &shaderName, QOpenGLShaderProgram *program);
void addShaderProgram(const QString &shaderName, QOpenGLShaderProgram *program,
2016-06-15 18:43:10 +12:00
const QDateTime &lastModified);
bool removeShaderProgram(const QString &shaderName);
2016-03-19 06:57:51 +13:00
2017-07-01 16:51:18 +12:00
QOpenGLShaderProgram *shaderProgram(const QString &shaderName) const;
2016-06-15 18:43:10 +12:00
QDateTime lastModified(const QString &shaderName) const;
2016-03-19 06:57:51 +13:00
2017-07-01 16:51:18 +12:00
std::pair<QOpenGLShaderProgram *, QDateTime> shaderData(
2016-06-15 18:43:10 +12:00
const QString &shaderName) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
GLuint loadTexture(const TRasterP &src, GLuint texUnit); //!< Loads a texture
2016-06-20 14:23:05 +12:00
//! and binds it to
//! the specified
//! texture unit.
2016-06-15 18:43:10 +12:00
//! \return The OpenGL texture id of the loaded texture. \param src
//! Loaded texture. \param texUnit Unit the texture will be bound to.
void unloadTexture(GLuint texId); //!< Releases the specified texture id.
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Renders the active shader program to the specified raster.
void draw(const TRasterP &dst);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Performs transform feedback with the specified varying variables
void transformFeedback(int varyingsCount, const GLsizeiptr *varyingSizes,
GLvoid **bufs);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
struct Imp;
std::unique_ptr<Imp> m_imp;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Not copyable
ShadingContext(const ShadingContext &);
ShadingContext &operator=(const ShadingContext &);
2016-03-19 06:57:51 +13:00
};
2017-07-01 16:51:18 +12:00
class TQOpenGLWidget : public QOpenGLWidget {
public:
TQOpenGLWidget();
void initializeGL() override;
};
2016-06-15 18:43:10 +12:00
#endif // SHADINGCONTEXT_H