Commit 249ab83a by Ludmány Balázs

Borderline working version

parent d4f375e9
Pipeline #125 skipped in 0 seconds
...@@ -33,4 +33,6 @@ HEADERS += \ ...@@ -33,4 +33,6 @@ HEADERS += \
DISTFILES += \ DISTFILES += \
draw_shader.fsh \ draw_shader.fsh \
draw_shader.vsh draw_shader.vsh \
fill_shader.vsh \
fill_shader.fsh
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2016-07-06T14:51:57. --> <!-- Written by QtCreator 3.5.1, 2016-07-07T10:36:53. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -39,7 +39,7 @@ void Dispatcher::GotBitmap(rfbClient *client, const uint8_t *buffer, int x, int ...@@ -39,7 +39,7 @@ void Dispatcher::GotBitmap(rfbClient *client, const uint8_t *buffer, int x, int
img = QImage(buffer, w, h, QImage::Format_RGB16); img = QImage(buffer, w, h, QImage::Format_RGB16);
break; break;
case 32: case 32:
img = QImage(buffer, w, h, QImage::Format_RGB32); img = QImage(buffer, w, h, QImage::Format_RGBX8888);
break; break;
default: default:
emit dispatcher->error(); emit dispatcher->error();
...@@ -74,6 +74,18 @@ void Dispatcher::FinishedFrameBufferUpdate(rfbClient *client) ...@@ -74,6 +74,18 @@ void Dispatcher::FinishedFrameBufferUpdate(rfbClient *client)
} }
} }
void Dispatcher::setMouse(int x, int y, bool left, bool middle, bool right)
{
if(m_client == NULL)
return;
int buttonMask = 0;
if(left) buttonMask |= rfbButton1Mask;
if(middle) buttonMask |= rfbButton2Mask;
if(right) buttonMask |= rfbButton3Mask;
SendPointerEvent(m_client, x, y, buttonMask);
}
unsigned int Dispatcher::decoderCount() const unsigned int Dispatcher::decoderCount() const
{ {
return m_decoderCount; return m_decoderCount;
...@@ -133,6 +145,14 @@ unsigned int Dispatcher::draw_count() ...@@ -133,6 +145,14 @@ unsigned int Dispatcher::draw_count()
return 0; return 0;
} }
QVector3D Dispatcher::colorMax() const
{
if(m_client == NULL)
return QVector3D();
return QVector3D(m_client->format.redMax, m_client->format.greenMax, m_client->format.blueMax);
}
void Dispatcher::create_context(QOpenGLContext *context) void Dispatcher::create_context(QOpenGLContext *context)
{ {
m_uploader.create_context(context); m_uploader.create_context(context);
...@@ -170,19 +190,23 @@ void Dispatcher::refresh() ...@@ -170,19 +190,23 @@ void Dispatcher::refresh()
setFinished(false); setFinished(false);
m_uploader.startedUpdate(); m_uploader.startedUpdate();
int message = 0;
int message = WaitForMessage(m_client, 10000); // Wait until we get something
if(message < 0) { while(message == 0) {
terminate(); message = WaitForMessage(m_client, 10000);
emit error(); if(message < 0) {
return;
}
if (message) {
if(!HandleRFBServerMessage(m_client)) {
terminate(); terminate();
emit error(); emit error();
return; return;
} }
if (message) {
if(!HandleRFBServerMessage(m_client)) {
terminate();
emit error();
return;
}
}
} }
} }
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <QPoint> #include <QPoint>
#include <QSize> #include <QSize>
#include <QColor> #include <QColor>
#include <QMouseEvent>
#include <QVector3D>
#include <rfb/rfbclient.h> #include <rfb/rfbclient.h>
#include "uploader.h" #include "uploader.h"
...@@ -29,6 +31,7 @@ public: ...@@ -29,6 +31,7 @@ public:
static rfbBool GotJpeg(rfbClient* client, const uint8_t* buffer, int length, int x, int y, int w, int h); static rfbBool GotJpeg(rfbClient* client, const uint8_t* buffer, int length, int x, int y, int w, int h);
static void FinishedFrameBufferUpdate(rfbClient* client); static void FinishedFrameBufferUpdate(rfbClient* client);
void setMouse(int x, int y, bool left, bool middle, bool right);
unsigned int decoderCount() const; unsigned int decoderCount() const;
unsigned int incrementDecoderCount(); unsigned int incrementDecoderCount();
...@@ -42,6 +45,7 @@ public: ...@@ -42,6 +45,7 @@ public:
unsigned int copy_count(); unsigned int copy_count();
unsigned int draw_count(); unsigned int draw_count();
QVector3D colorMax() const;
private: private:
rfbClient *m_client; rfbClient *m_client;
unsigned int m_decoderCount; unsigned int m_decoderCount;
......
...@@ -3,6 +3,5 @@ varying highp vec2 vartexcoord; ...@@ -3,6 +3,5 @@ varying highp vec2 vartexcoord;
void main(void) void main(void)
{ {
gl_FragColor = texture2D(texture, vartexcoord); gl_FragColor = vec4(texture2D(texture, vartexcoord).rgb, 1.0);
} }
varying highp vec3 varcolor;
void main(void)
{
gl_FragColor = vec4(varcolor, 1.0);
}
uniform highp mat4 ortho;
uniform highp vec3 colormax;
attribute highp vec2 position;
attribute highp vec3 color;
varying highp vec3 varcolor;
void main(void)
{
gl_Position = ortho * vec4(position, 0.0, 1.0);
varcolor = color / colormax;
}
...@@ -8,7 +8,7 @@ int main(int argc, char *argv[]) ...@@ -8,7 +8,7 @@ int main(int argc, char *argv[])
{ {
QGuiApplication app(argc, argv); QGuiApplication app(argc, argv);
qmlRegisterType<QVnc>("thinclient", 1, 1, "QVnc"); qmlRegisterType<QVnc>("thinclient", 1, 3, "QVnc");
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
import QtQuick 2.6 import QtQuick 2.6
import QtQuick.Controls 2.0 import QtQuick.Controls 2.0
import thinclient 1.1 import thinclient 1.3
ApplicationWindow { ApplicationWindow {
visible: true visible: true
width: 1280 width: vnc.width;
height: 1024 height: tab.height + vnc.height
header: TabBar { header: TabBar {
id: tab
width: parent.width width: parent.width
TabButton { TabButton {
text: qsTr("Open connection") text: qsTr("Open connection")
...@@ -26,7 +27,29 @@ ApplicationWindow { ...@@ -26,7 +27,29 @@ ApplicationWindow {
id: vnc id: vnc
host: "vm.ik.bme.hu" host: "vm.ik.bme.hu"
port: 10495 port: 10495
width: 1280 width: 1027
height: 1024 height: 768
MouseArea {
anchors.fill: parent
cursorShape: Qt.BlankCursor
hoverEnabled: true
acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton
onPositionChanged: vnc.setMouse(mouse.x,
mouse.y,
mouse.buttons & Qt.LeftButton,
mouse.buttons & Qt.MiddleButton,
mouse.buttons & Qt.RightButton)
onPressed: vnc.setMouse(mouse.x,
mouse.y,
mouse.buttons & Qt.LeftButton,
mouse.buttons & Qt.MiddleButton,
mouse.buttons & Qt.RightButton)
onReleased: vnc.setMouse(mouse.x,
mouse.y,
mouse.buttons & Qt.LeftButton,
mouse.buttons & Qt.MiddleButton,
mouse.buttons & Qt.RightButton)
}
} }
} }
...@@ -56,6 +56,11 @@ void QVnc::setPort(int port) ...@@ -56,6 +56,11 @@ void QVnc::setPort(int port)
emit portChanged(port); emit portChanged(port);
} }
void QVnc::setMouse(int x, int y, bool left, bool middle, bool right)
{
m_dispatcher->setMouse(x, y, left, middle, right);
}
void QVnc::dispatch_error() void QVnc::dispatch_error()
{ {
qDebug() << "error"; qDebug() << "error";
...@@ -81,6 +86,7 @@ QQuickFramebufferObject::Renderer *QVnc::createRenderer() const ...@@ -81,6 +86,7 @@ QQuickFramebufferObject::Renderer *QVnc::createRenderer() const
m_dispatcher->uploader().draw_buffer(), m_dispatcher->uploader().draw_buffer(),
m_dispatcher->uploader().draw_textures()); m_dispatcher->uploader().draw_textures());
connect(renderer, &VncRenderer::finishedRendering, m_dispatcher, &Dispatcher::refresh); connect(renderer, &VncRenderer::finishedRendering, m_dispatcher, &Dispatcher::refresh);
connect(renderer, &VncRenderer::framebufferObjectChanged, &(m_dispatcher->uploader()), &Uploader::changeFramebufferObject);
return renderer; return renderer;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <QQuickFramebufferObject> #include <QQuickFramebufferObject>
#include <QThread> #include <QThread>
#include <QOffscreenSurface> #include <QOffscreenSurface>
#include <QMouseEvent>
#include "dispatcher.h" #include "dispatcher.h"
#include "vncrenderer.h" #include "vncrenderer.h"
...@@ -41,6 +42,7 @@ public slots: ...@@ -41,6 +42,7 @@ public slots:
void setHost(QString host); void setHost(QString host);
void setPort(int port); void setPort(int port);
void setMouse(int x, int y, bool left, bool middle, bool right);
void dispatch_error(); void dispatch_error();
private: private:
......
...@@ -14,9 +14,6 @@ Uploader::Uploader() ...@@ -14,9 +14,6 @@ Uploader::Uploader()
m_copy_data.reserve(5); m_copy_data.reserve(5);
m_copy_source->reserve(5); m_copy_source->reserve(5);
m_draw_textures->reserve(5); m_draw_textures->reserve(5);
m_draw_buffer = QSharedPointer<QOpenGLBuffer>(new QOpenGLBuffer);
m_draw_buffer->setUsagePattern(QOpenGLBuffer::DynamicDraw);
} }
void Uploader::create_context(QOpenGLContext *context) void Uploader::create_context(QOpenGLContext *context)
...@@ -25,33 +22,57 @@ void Uploader::create_context(QOpenGLContext *context) ...@@ -25,33 +22,57 @@ void Uploader::create_context(QOpenGLContext *context)
m_uploader_context->setShareContext(context); m_uploader_context->setShareContext(context);
m_uploader_context->create(); m_uploader_context->create();
m_uploader_context->makeCurrent(&m_surface); m_uploader_context->makeCurrent(&m_surface);
m_uploader_context->functions()->initializeOpenGLFunctions();
m_fill_buffer.create();
m_copy_buffer.create();
m_draw_buffer.create();
} }
void Uploader::startedUpdate() void Uploader::startedUpdate()
{ {
// Clean up the data from the previous round // Clean up the data from the previous round
m_fill_data.clear();
m_fill_count = 0;
for(unsigned int i = 0; i < m_copy_count; i++) { for(unsigned int i = 0; i < m_copy_count; i++) {
m_copy_source->at(i).texture->destroy(); m_copy_source->at(i).texture->destroy();
delete m_copy_source->at(i).texture; delete m_copy_source->at(i).texture;
} }
m_copy_source->clear();
m_copy_data.clear(); m_copy_data.clear();
m_copy_count = 0; m_copy_count = 0;
m_fill_data.clear();
m_fill_count = 0;
for(unsigned int i = 0; i < m_draw_count; i++) { for(unsigned int i = 0; i < m_draw_count; i++) {
m_draw_textures->at(i)->destroy(); m_draw_textures->at(i)->destroy();
delete m_draw_textures->at(i); delete m_draw_textures->at(i);
} }
m_draw_textures->clear();
m_draw_data.clear(); m_draw_data.clear();
m_draw_count = 0; m_draw_count = 0;
} }
void Uploader::gotCopyRect(const int src_x, const int src_y, const int width, const int height, const int dest_x, const int dest_y) void Uploader::gotCopyRect(const int src_x, const int src_y, const int width, const int height, const int dest_x, const int dest_y)
{ {
if(m_framebufferObject != NULL && !m_framebufferObject->isBound())
m_framebufferObject->bind();
QOpenGLTexture* texture = new QOpenGLTexture(QOpenGLTexture::Target2D); QOpenGLTexture* texture = new QOpenGLTexture(QOpenGLTexture::Target2D);
texture->allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::Float32); texture->setAutoMipMapGenerationEnabled(false);
texture->setSize(width, height);
texture->setFormat(QOpenGLTexture::RGBAFormat);
texture->allocateStorage();
texture->bind();
m_uploader_context->functions()->glCopyTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
src_x,
m_framebufferHeight - src_y,
width,
height,
0);
texture->release();
// "Specify the window coordinates of the lower left corner // "Specify the window coordinates of the lower left corner
// of the rectangular region of pixels to be copied." // of the rectangular region of pixels to be copied."
...@@ -124,7 +145,7 @@ void Uploader::gotFillRect(const int x, const int y, const int width, const int ...@@ -124,7 +145,7 @@ void Uploader::gotFillRect(const int x, const int y, const int width, const int
void Uploader::gotBitmap(const QImage &image, const int x, const int y, const int width, const int height) void Uploader::gotBitmap(const QImage &image, const int x, const int y, const int width, const int height)
{ {
m_draw_textures->append(new QOpenGLTexture(image, QOpenGLTexture::DontGenerateMipMaps)); m_draw_textures->append(new QOpenGLTexture(image.mirrored(), QOpenGLTexture::DontGenerateMipMaps));
// bottom left // bottom left
m_draw_data.append((float) x); m_draw_data.append((float) x);
...@@ -152,23 +173,26 @@ void Uploader::gotBitmap(const QImage &image, const int x, const int y, const in ...@@ -152,23 +173,26 @@ void Uploader::gotBitmap(const QImage &image, const int x, const int y, const in
void Uploader::finishedUpdate() void Uploader::finishedUpdate()
{ {
if(m_copy_count > 0) { if(m_fill_count > 0) {
m_copy_buffer->bind(); m_fill_buffer.bind();
m_copy_buffer->allocate(m_copy_data.constData(), m_copy_data.size() * sizeof(float)); m_fill_buffer.allocate(m_fill_data.constData(), m_fill_data.size() * sizeof(float));
m_copy_buffer->release(); m_fill_buffer.release();
} }
if(m_fill_count > 0) { if(m_copy_count > 0) {
m_fill_buffer->bind(); m_copy_buffer.bind();
m_fill_buffer->allocate(m_fill_data.constData(), m_fill_data.size() * sizeof(float)); m_copy_buffer.allocate(m_copy_data.constData(), m_copy_data.size() * sizeof(float));
m_fill_buffer->release(); m_copy_buffer.release();
} }
if(m_draw_count > 0) { if(m_draw_count > 0) {
m_draw_buffer->bind(); m_draw_buffer.bind();
m_draw_buffer->allocate(m_draw_data.data(), m_draw_data.size() * sizeof(float)); m_draw_buffer.allocate(m_draw_data.data(), m_draw_data.size() * sizeof(float));
m_draw_buffer->release(); m_draw_buffer.release();
} }
QOpenGLContext::currentContext()->functions()->glFlush();
if(m_framebufferObject != NULL && m_framebufferObject->isBound())
m_framebufferObject->release();
} }
void Uploader::setFramebufferHeight(int framebufferHeight) void Uploader::setFramebufferHeight(int framebufferHeight)
...@@ -191,22 +215,22 @@ unsigned int Uploader::draw_count() const ...@@ -191,22 +215,22 @@ unsigned int Uploader::draw_count() const
return m_draw_count; return m_draw_count;
} }
QSharedPointer<QVector<copy>> Uploader::copy_source() QOpenGLBuffer Uploader::fill_buffer()
{ {
return m_copy_source; return m_fill_buffer;
} }
QSharedPointer<QOpenGLBuffer> Uploader::copy_buffer() QSharedPointer<QVector<copy>> Uploader::copy_source()
{ {
return m_copy_buffer; return m_copy_source;
} }
QSharedPointer<QOpenGLBuffer> Uploader::fill_buffer() QOpenGLBuffer Uploader::copy_buffer()
{ {
return m_fill_buffer; return m_copy_buffer;
} }
QSharedPointer<QOpenGLBuffer> Uploader::draw_buffer() QOpenGLBuffer Uploader::draw_buffer()
{ {
return m_draw_buffer; return m_draw_buffer;
} }
...@@ -216,7 +240,7 @@ QSharedPointer<QVector<QOpenGLTexture *>> Uploader::draw_textures() ...@@ -216,7 +240,7 @@ QSharedPointer<QVector<QOpenGLTexture *>> Uploader::draw_textures()
return m_draw_textures; return m_draw_textures;
} }
QOpenGLContext *Uploader::uploader_context() const void Uploader::changeFramebufferObject(QOpenGLFramebufferObject *framebufferObject)
{ {
return m_uploader_context; m_framebufferObject = framebufferObject;
} }
#ifndef UPLOADER_H #ifndef UPLOADER_H
#define UPLOADER_H #define UPLOADER_H
#include <QObject>
#include <QQuickWindow> #include <QQuickWindow>
#include <QDebug> #include <QDebug>
#include <QVector> #include <QVector>
...@@ -9,6 +10,7 @@ ...@@ -9,6 +10,7 @@
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <QOpenGLBuffer> #include <QOpenGLBuffer>
#include <QOpenGLTexture> #include <QOpenGLTexture>
#include <QOpenGLFramebufferObject>
#include <QThreadPool> #include <QThreadPool>
#include <QtAlgorithms> #include <QtAlgorithms>
#include <QSharedPointer> #include <QSharedPointer>
...@@ -21,8 +23,9 @@ typedef struct { ...@@ -21,8 +23,9 @@ typedef struct {
QOpenGLTexture *texture; QOpenGLTexture *texture;
} copy; } copy;
class Uploader class Uploader : public QObject
{ {
Q_OBJECT
public: public:
Uploader(); Uploader();
void create_context(QOpenGLContext *context); void create_context(QOpenGLContext *context);
...@@ -38,34 +41,37 @@ public: ...@@ -38,34 +41,37 @@ public:
unsigned int copy_count() const; unsigned int copy_count() const;
unsigned int draw_count() const; unsigned int draw_count() const;
QOpenGLBuffer fill_buffer();
QSharedPointer<QVector<copy>> copy_source(); QSharedPointer<QVector<copy>> copy_source();
QSharedPointer<QOpenGLBuffer> copy_buffer(); QOpenGLBuffer copy_buffer();
QSharedPointer<QOpenGLBuffer> fill_buffer(); QOpenGLBuffer draw_buffer();
QSharedPointer<QOpenGLBuffer> draw_buffer();
QSharedPointer<QVector<QOpenGLTexture *>> draw_textures(); QSharedPointer<QVector<QOpenGLTexture *>> draw_textures();
QOpenGLContext *uploader_context() const;
private: private:
int m_framebufferHeight; int m_framebufferHeight;
QOffscreenSurface m_surface; QOffscreenSurface m_surface;
QOpenGLContext *m_uploader_context; QOpenGLContext *m_uploader_context;
unsigned int m_copy_count; QOpenGLFramebufferObject *m_framebufferObject;
QVector<float> m_copy_data;
QSharedPointer<QVector<copy>> m_copy_source;
QSharedPointer<QOpenGLBuffer> m_copy_buffer;
unsigned int m_fill_count; unsigned int m_fill_count;
QVector<float> m_fill_data; QVector<float> m_fill_data;
QSharedPointer<QOpenGLBuffer> m_fill_buffer; QOpenGLBuffer m_fill_buffer;
unsigned int m_copy_count;
QVector<float> m_copy_data;
QSharedPointer<QVector<copy>> m_copy_source;
QOpenGLBuffer m_copy_buffer;
unsigned int m_draw_count; unsigned int m_draw_count;
QVector<float> m_draw_data; QVector<float> m_draw_data;
QSharedPointer<QOpenGLBuffer> m_draw_buffer; QOpenGLBuffer m_draw_buffer;
QSharedPointer<QVector<QOpenGLTexture*>> m_draw_textures; QSharedPointer<QVector<QOpenGLTexture*>> m_draw_textures;
uchar m_decoders_running; uchar m_decoders_running;
public slots:
void changeFramebufferObject(QOpenGLFramebufferObject *framebufferObject);
}; };
#endif // UPLOADER_H #endif // UPLOADER_H
#include "vncrenderer.h" #include "vncrenderer.h"
VncRenderer::VncRenderer(QQuickWindow *window, VncRenderer::VncRenderer(QQuickWindow *window,
QSharedPointer<QOpenGLBuffer> fill_buffer, QOpenGLBuffer fill_buffer,
QSharedPointer<QVector<copy>> copy_source, QSharedPointer<QVector<copy>> copy_source,
QSharedPointer<QOpenGLBuffer> copy_buffer, QOpenGLBuffer copy_buffer,
QSharedPointer<QOpenGLBuffer> draw_buffer, QOpenGLBuffer draw_buffer,
QSharedPointer<QVector<QOpenGLTexture*>> draw_textures, QSharedPointer<QVector<QOpenGLTexture*>> draw_textures,
QObject *parent) : QObject *parent) :
QObject(parent), m_window(window), m_fill_buffer(fill_buffer), m_copy_source(copy_source), QObject(parent), m_window(window), m_clear(true), m_fill_buffer(fill_buffer), m_copy_source(copy_source),
m_copy_buffer(copy_buffer), m_draw_buffer(draw_buffer), m_draw_textures(draw_textures), m_clear(true) m_copy_buffer(copy_buffer), m_draw_buffer(draw_buffer), m_draw_textures(draw_textures)
{ {
m_draw_buffer->create(); m_fill_program.addShaderFromSourceFile(QOpenGLShader::Vertex, "fill_shader.vsh");
/*QOpenGLShader fill_vshader(QOpenGLShader::Vertex, &m_fill_program); m_fill_program.addShaderFromSourceFile(QOpenGLShader::Fragment, "fill_shader.fsh");
fill_vshader.compileSourceCode("uniform highp mat4 ortho;\n" m_fill_program.bind();
"attribute highp vec2 position;\n"
"attribute lowp vec3 color;\n"
"varying lowp vec4 varcolor;\n"
"void main(void)\n"
"{\n"
" varcolor = vec4(color, 1.0);\n"
" gl_Position = ortho * vec4(position, 0.0, 1.0);\n"
"}\n");
QOpenGLShader fill_fshader(QOpenGLShader::Fragment, &m_fill_program);
fill_fshader.compileSourceCode("varying lowp vec4 varcolor;\n"
"void main(void)\n"
"{\n"
" gl_FragColor = varcolor;\n"
"}\n");
m_fill_program.addShader(&fill_vshader);
m_fill_program.addShader(&fill_fshader);
m_fill_program.link();
m_fill_program.enableAttributeArray("position"); m_fill_program.enableAttributeArray("position");
m_fill_program.enableAttributeArray("color");*/ m_fill_program.enableAttributeArray("color");
m_fill_program.release();
m_draw_program.addShaderFromSourceFile(QOpenGLShader::Vertex, "draw_shader.vsh"); m_draw_program.addShaderFromSourceFile(QOpenGLShader::Vertex, "draw_shader.vsh");
m_draw_program.addShaderFromSourceFile(QOpenGLShader::Fragment, "draw_shader.fsh"); m_draw_program.addShaderFromSourceFile(QOpenGLShader::Fragment, "draw_shader.fsh");
...@@ -42,34 +24,36 @@ VncRenderer::VncRenderer(QQuickWindow *window, ...@@ -42,34 +24,36 @@ VncRenderer::VncRenderer(QQuickWindow *window,
m_draw_program.enableAttributeArray("position"); m_draw_program.enableAttributeArray("position");
m_draw_program.enableAttributeArray("texcoord"); m_draw_program.enableAttributeArray("texcoord");
m_draw_program.release(); m_draw_program.release();
m_functions = QOpenGLContext::currentContext()->functions();
} }
void VncRenderer::render() void VncRenderer::render()
{ {
QOpenGLFunctions *fun = m_window->openglContext()->functions();
if(m_clear) { if(m_clear) {
fun->glClearColor(1.0f, 0.0f, 0.0f, 1.0f); m_functions->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
fun->glClear(GL_COLOR_BUFFER_BIT); m_functions->glClear(GL_COLOR_BUFFER_BIT);
m_clear = false; m_clear = false;
} }
/*if(m_fill_count > 0) { if(m_fill_count > 0) {
m_fill_program.bind(); m_fill_program.bind();
m_fill_program.enableAttributeArray("position");
m_fill_program.enableAttributeArray("color");
m_fill_buffer.bind(); m_fill_buffer.bind();
m_fill_program.setAttributeBuffer("position", GL_FLOAT, 0, 2, 3 * sizeof(float)); m_fill_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 5 * sizeof(float));
m_fill_program.setAttributeBuffer("color", GL_FLOAT, 2, 3, 2 * sizeof(float)); m_fill_program.setAttributeBuffer("color", GL_FLOAT, 2 * sizeof(float), 3, 5 * sizeof(float));
for(unsigned int i = 0; i < m_fill_count; i++) for(unsigned int i = 0; i < m_fill_count; i++)
fun->glDrawArrays(GL_TRIANGLES, i * 4, 4); m_functions->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4);
m_fill_buffer.release(); m_fill_buffer.release();
m_fill_program.release(); m_fill_program.release();
} }
*/
if(m_copy_count > 0 || m_draw_count > 0) if(m_copy_count > 0 || m_draw_count > 0)
m_draw_program.bind(); m_draw_program.bind();
m_draw_program.enableAttributeArray("position"); m_draw_program.enableAttributeArray("position");
m_draw_program.enableAttributeArray("texcoord"); m_draw_program.enableAttributeArray("texcoord");
/*
if(m_copy_count > 0){ if(m_copy_count > 0){
m_copy_buffer.bind(); m_copy_buffer.bind();
m_draw_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 4 * sizeof(float)); m_draw_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 4 * sizeof(float));
...@@ -77,32 +61,32 @@ void VncRenderer::render() ...@@ -77,32 +61,32 @@ void VncRenderer::render()
for(unsigned int i = 0; i < m_copy_count; i++) { for(unsigned int i = 0; i < m_copy_count; i++) {
m_copy_source->at(i).texture->bind(); m_copy_source->at(i).texture->bind();
fun->glCopyTexImage2D(GL_TEXTURE_2D, /*m_functions->glCopyTexImage2D(GL_TEXTURE_2D,
0, 0,
GL_RGBA, GL_RGBA,
m_copy_source->at(i).src_x, m_copy_source->at(i).src_x,
m_copy_source->at(i).src_y, m_copy_source->at(i).src_y,
m_copy_source->at(i).width, m_copy_source->at(i).width,
m_copy_source->at(i).height, m_copy_source->at(i).height,
0); 0);*/
fun->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4); m_functions->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4);
m_copy_source->at(i).texture->release(); m_copy_source->at(i).texture->release();
} }
m_copy_buffer.release(); m_copy_buffer.release();
}*/ }
if(m_draw_count > 0) { if(m_draw_count > 0) {
m_draw_buffer->bind(); m_draw_buffer.bind();
m_draw_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 4 * sizeof(float)); m_draw_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 4 * sizeof(float));
m_draw_program.setAttributeBuffer("texcoord", GL_FLOAT, 2 * sizeof(float), 2, 4 * sizeof(float)); m_draw_program.setAttributeBuffer("texcoord", GL_FLOAT, 2 * sizeof(float), 2, 4 * sizeof(float));
for(unsigned int i = 0; i < m_draw_count; i++) { for(unsigned int i = 0; i < m_draw_count; i++) {
m_draw_textures->at(i)->bind(); m_draw_textures->at(i)->bind();
fun->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4); m_functions->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4);
m_draw_textures->at(i)->release(); m_draw_textures->at(i)->release();
} }
m_draw_buffer->release(); m_draw_buffer.release();
} }
if(m_copy_count > 0 || m_draw_count > 0) if(m_copy_count > 0 || m_draw_count > 0)
...@@ -117,13 +101,15 @@ QOpenGLFramebufferObject *VncRenderer::createFramebufferObject(const QSize &size ...@@ -117,13 +101,15 @@ QOpenGLFramebufferObject *VncRenderer::createFramebufferObject(const QSize &size
{ {
QMatrix4x4 ortho; QMatrix4x4 ortho;
ortho.ortho(QRect(QPoint(0, size.height()), QSize(size.width(), -1 * size.height()))); ortho.ortho(QRect(QPoint(0, size.height()), QSize(size.width(), -1 * size.height())));
//m_fill_program.bind(); m_fill_program.bind();
//m_fill_program.setUniformValue("ortho", ortho); m_fill_program.setUniformValue("ortho", ortho);
m_draw_program.bind(); m_draw_program.bind();
m_draw_program.setUniformValue("ortho", ortho); m_draw_program.setUniformValue("ortho", ortho);
m_draw_program.release(); m_draw_program.release();
return new QOpenGLFramebufferObject(size); QOpenGLFramebufferObject *framebufferObject = new QOpenGLFramebufferObject(size);
emit framebufferObjectChanged(framebufferObject);
return framebufferObject;
} }
void VncRenderer::synchronize(QQuickFramebufferObject *object) void VncRenderer::synchronize(QQuickFramebufferObject *object)
...@@ -133,4 +119,8 @@ void VncRenderer::synchronize(QQuickFramebufferObject *object) ...@@ -133,4 +119,8 @@ void VncRenderer::synchronize(QQuickFramebufferObject *object)
m_fill_count = dispatcher->fill_count(); m_fill_count = dispatcher->fill_count();
m_copy_count = dispatcher->copy_count(); m_copy_count = dispatcher->copy_count();
m_draw_count = dispatcher->draw_count(); m_draw_count = dispatcher->draw_count();
m_fill_program.bind();
m_fill_program.setUniformValue("colormax", dispatcher->colorMax());
m_fill_program.release();
} }
...@@ -18,11 +18,11 @@ class VncRenderer : public QObject, public QQuickFramebufferObject::Renderer ...@@ -18,11 +18,11 @@ class VncRenderer : public QObject, public QQuickFramebufferObject::Renderer
{ {
Q_OBJECT Q_OBJECT
public: public:
VncRenderer(QQuickWindow* window, VncRenderer(QQuickWindow *window,
QSharedPointer<QOpenGLBuffer> fill_buffer, QOpenGLBuffer fill_buffer,
QSharedPointer<QVector<copy>> copy_source, QSharedPointer<QVector<copy>> copy_source,
QSharedPointer<QOpenGLBuffer> copy_buffer, QOpenGLBuffer copy_buffer,
QSharedPointer<QOpenGLBuffer> draw_buffer, QOpenGLBuffer draw_buffer,
QSharedPointer<QVector<QOpenGLTexture*>> draw_textures, QSharedPointer<QVector<QOpenGLTexture*>> draw_textures,
QObject *parent = 0); QObject *parent = 0);
protected: protected:
...@@ -31,24 +31,23 @@ protected: ...@@ -31,24 +31,23 @@ protected:
void synchronize(QQuickFramebufferObject *) override; void synchronize(QQuickFramebufferObject *) override;
private: private:
QQuickWindow *m_window; QQuickWindow *m_window;
QOpenGLFunctions *m_functions;
bool m_clear;
unsigned int m_fill_count; unsigned int m_fill_count;
QOpenGLShaderProgram m_fill_program; QOpenGLShaderProgram m_fill_program;
QSharedPointer<QOpenGLBuffer> m_fill_buffer; QOpenGLBuffer m_fill_buffer;
unsigned int m_copy_count; unsigned int m_copy_count;
QSharedPointer<QVector<copy>> m_copy_source; QSharedPointer<QVector<copy>> m_copy_source;
QSharedPointer<QOpenGLBuffer> m_copy_buffer; QOpenGLBuffer m_copy_buffer;
unsigned int m_draw_count; unsigned int m_draw_count;
QOpenGLShaderProgram m_draw_program; QOpenGLShaderProgram m_draw_program;
QSharedPointer<QOpenGLBuffer> m_draw_buffer; QOpenGLBuffer m_draw_buffer;
QSharedPointer<QVector<QOpenGLTexture*>> m_draw_textures; QSharedPointer<QVector<QOpenGLTexture*>> m_draw_textures;
QMatrix4x4 m_ortho;
bool m_clear;
signals: signals:
void framebufferObjectChanged(QOpenGLFramebufferObject *framebufferObject);
void finishedRendering(); void finishedRendering();
}; };
......
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 sign in to comment