Commit d6d111f3 authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas

try to debug glsl 150

parent 8ff0daa9
......@@ -62,8 +62,10 @@ dtkWidgetsWidget *dtkVisualizationViewerStack::create(const QString& type)
view = new dtkVisualizationView3D;
else if (type == "View3D")
view = new dtkVisualizationView3D;
else if (type == "ViewVideoPlayer")
else if (type == "ViewVideoPlayer") {
view = new dtkVisualizationViewVideoPlayer;
dynamic_cast<dtkVisualizationViewVideoGL*>(view)->setVersion(4, 1, false);
}
return view;
}
......
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource prefix="">
<file>dtkVisualizationViewVideoGL.vert</file>
<file>dtkVisualizationViewVideoGL.frag</file>
<file>dtkVisualizationViewVideoGL.120.vert</file>
<file>dtkVisualizationViewVideoGL.120.frag</file>
<file>dtkVisualizationViewVideoGL.150.vert</file>
<file>dtkVisualizationViewVideoGL.150.frag</file>
</qresource>
</RCC>
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#version 410
uniform sampler2D tex;
in vec2 coord;
out vec4 color;
void main()
{
// color = vec4( abs(coord.x), abs(coord.y), 0.0, 1);
color = vec4(texture(tex, coord));
}
//
// dtkVisualizationViewVideoGL.frag ends here
// Version: $Id$
//
//
// Commentary:
//
//
// Change Log:
//
//
// Code:
#version 410
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
in vec3 vertexPosition;
in vec3 vertexNormal;
in vec2 texCoord2d;
out vec2 coord;
void main()
{
coord = texCoord2d;
gl_Position = projectionMatrix * modelViewMatrix * vec4(vertexPosition, 1);
}
//
// dtkVisualizationViewVideoGL.vert ends here
......@@ -35,6 +35,9 @@ public:
void resizeGL(int w, int h);
void paintGL(void);
public:
void setVersion(int major, int minor, bool debug);
public:
QMatrix4x4 projection_matrix, view_matrix;
QOpenGLShaderProgram pgm;
......@@ -53,6 +56,9 @@ public:
float rx;
float ry;
public:
dtkVisualizationViewVideoGL *q = nullptr;
public:
QString title;
};
......@@ -61,20 +67,38 @@ dtkVisualizationViewVideoGLPrivate::dtkVisualizationViewVideoGLPrivate(QWidget *
vbo(QOpenGLBuffer::VertexBuffer),
ibo(QOpenGLBuffer::IndexBuffer)
{
QSurfaceFormat format;
}
void dtkVisualizationViewVideoGLPrivate::setVersion( int major, int minor, bool debug)
{
QSurfaceFormat format;
format.setVersion(major, minor);
format.setDepthBufferSize(1);
format.setAlphaBufferSize(1);
format.setStencilBufferSize(1);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setOption(QSurfaceFormat::DeprecatedFunctions);
format.setOption(QSurfaceFormat::ResetNotification);
if (debug) {
format.setOption(QSurfaceFormat::DebugContext);
}
this->setFormat(format);
if (major == 3)
q->version = dtkVisualizationViewVideoGL::GLSL150;
else
q->version = dtkVisualizationViewVideoGL::GLSL120;
}
void dtkVisualizationViewVideoGLPrivate::createShaderProgram(void)
{
if(!pgm.addShaderFromSourceFile(QOpenGLShader::Vertex, ":dtkVisualizationViewVideoGL.vert")) {
if(!pgm.addShaderFromSourceFile(QOpenGLShader::Vertex, q->version == dtkVisualizationViewVideoGL::GLSL120 ? ":dtkVisualizationViewVideoGL.120.vert" : ":dtkVisualizationViewVideoGL.150.vert")) {
qDebug() << "Error in vertex shader:" << pgm.log();
exit(1);
}
if(!pgm.addShaderFromSourceFile(QOpenGLShader::Fragment, ":dtkVisualizationViewVideoGL.frag")) {
if(!pgm.addShaderFromSourceFile(QOpenGLShader::Fragment, q->version == dtkVisualizationViewVideoGL::GLSL120 ? ":dtkVisualizationViewVideoGL.120.frag" : ":dtkVisualizationViewVideoGL.150.frag")) {
qDebug() << "Error in fragment shader:" << pgm.log();
exit(1);
}
......@@ -198,16 +222,29 @@ void dtkVisualizationViewVideoGLPrivate::paintGL(void)
createGeometry();
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
QOpenGLContext *context = QOpenGLContext::currentContext();
bool enable = context->hasExtension(QByteArrayLiteral("GL_KHR_debug"));
static QOpenGLDebugLogger *logger = new QOpenGLDebugLogger(this);
if (enable)
logger->initialize(); // initializes in the current context, i.e. ctx
// ///////////////////////////////////////////////////////////////////
this->glGenTextures(1, &tex);
this->glBindTexture (GL_TEXTURE_2D, tex);
this->glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
this->glTexImage2D (GL_TEXTURE_2D, 0, 4, this->buffer.width(), this->buffer.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, this->buffer.bits());
this->glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, this->buffer.width(), this->buffer.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, this->buffer.bits());
this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
this->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
......@@ -226,6 +263,18 @@ void dtkVisualizationViewVideoGLPrivate::paintGL(void)
vao.release();
vbo.release();
ibo.release();
// ///////////////////////////////////////////////////////////////////
//
// ///////////////////////////////////////////////////////////////////
if (enable) {
const QList<QOpenGLDebugMessage> messages = logger->loggedMessages();
for (const QOpenGLDebugMessage &message : messages)
qDebug() << message;
}
// ///////////////////////////////////////////////////////////////////
}
// ///////////////////////////////////////////////////////////////////
......@@ -235,6 +284,8 @@ void dtkVisualizationViewVideoGLPrivate::paintGL(void)
dtkVisualizationViewVideoGL::dtkVisualizationViewVideoGL(QWidget *parent) : dtkWidgetsWidget(parent)
{
d = new dtkVisualizationViewVideoGLPrivate(this);
d->q = this;
d->setVersion(2, 1, false);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
......@@ -246,9 +297,15 @@ dtkVisualizationViewVideoGL::~dtkVisualizationViewVideoGL(void)
{
delete d;
}
void dtkVisualizationViewVideoGL::setVersion( int major, int minor, bool debug)
{
d->setVersion(major, minor, debug);
}
QWidget *dtkVisualizationViewVideoGL::widget(void)
{
qDebug() << d->context();
qDebug() << d->format();
return d;
}
......
......@@ -24,6 +24,12 @@ class DTKVISUALIZATION_EXPORT dtkVisualizationViewVideoGL : public dtkWidgetsWid
{
Q_OBJECT
public:
enum Version {
GLSL120,
GLSL150
};
public:
dtkVisualizationViewVideoGL(QWidget *parent = nullptr);
~dtkVisualizationViewVideoGL(void);
......@@ -42,8 +48,18 @@ public:
float ratioBuffer(void) const;
float ratioWidget(void) const;
public:
void setVersion(int major, int minor, bool debug = false);
private:
Version version = GLSL120;
private:
class dtkVisualizationViewVideoGLPrivate *d;
private:
friend class dtkVisualizationViewVideoGLPrivate;
};
//
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment