Commit 249ab83a by Ludmány Balázs

Borderline working version

parent d4f375e9
Pipeline #125 skipped in 0 seconds
......@@ -33,4 +33,6 @@ HEADERS += \
DISTFILES += \
draw_shader.fsh \
draw_shader.vsh
draw_shader.vsh \
fill_shader.vsh \
fill_shader.fsh
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<data>
<variable>EnvironmentId</variable>
......
......@@ -39,7 +39,7 @@ void Dispatcher::GotBitmap(rfbClient *client, const uint8_t *buffer, int x, int
img = QImage(buffer, w, h, QImage::Format_RGB16);
break;
case 32:
img = QImage(buffer, w, h, QImage::Format_RGB32);
img = QImage(buffer, w, h, QImage::Format_RGBX8888);
break;
default:
emit dispatcher->error();
......@@ -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
{
return m_decoderCount;
......@@ -133,6 +145,14 @@ unsigned int Dispatcher::draw_count()
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)
{
m_uploader.create_context(context);
......@@ -170,19 +190,23 @@ void Dispatcher::refresh()
setFinished(false);
m_uploader.startedUpdate();
int message = 0;
int message = WaitForMessage(m_client, 10000);
if(message < 0) {
terminate();
emit error();
return;
}
if (message) {
if(!HandleRFBServerMessage(m_client)) {
// Wait until we get something
while(message == 0) {
message = WaitForMessage(m_client, 10000);
if(message < 0) {
terminate();
emit error();
return;
}
if (message) {
if(!HandleRFBServerMessage(m_client)) {
terminate();
emit error();
return;
}
}
}
}
......
......@@ -9,6 +9,8 @@
#include <QPoint>
#include <QSize>
#include <QColor>
#include <QMouseEvent>
#include <QVector3D>
#include <rfb/rfbclient.h>
#include "uploader.h"
......@@ -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 void FinishedFrameBufferUpdate(rfbClient* client);
void setMouse(int x, int y, bool left, bool middle, bool right);
unsigned int decoderCount() const;
unsigned int incrementDecoderCount();
......@@ -42,6 +45,7 @@ public:
unsigned int copy_count();
unsigned int draw_count();
QVector3D colorMax() const;
private:
rfbClient *m_client;
unsigned int m_decoderCount;
......
......@@ -3,6 +3,5 @@ varying highp vec2 vartexcoord;
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[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<QVnc>("thinclient", 1, 1, "QVnc");
qmlRegisterType<QVnc>("thinclient", 1, 3, "QVnc");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
......
import QtQuick 2.6
import QtQuick.Controls 2.0
import thinclient 1.1
import thinclient 1.3
ApplicationWindow {
visible: true
width: 1280
height: 1024
width: vnc.width;
height: tab.height + vnc.height
header: TabBar {
id: tab
width: parent.width
TabButton {
text: qsTr("Open connection")
......@@ -26,7 +27,29 @@ ApplicationWindow {
id: vnc
host: "vm.ik.bme.hu"
port: 10495
width: 1280
height: 1024
width: 1027
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)
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()
{
qDebug() << "error";
......@@ -81,6 +86,7 @@ QQuickFramebufferObject::Renderer *QVnc::createRenderer() const
m_dispatcher->uploader().draw_buffer(),
m_dispatcher->uploader().draw_textures());
connect(renderer, &VncRenderer::finishedRendering, m_dispatcher, &Dispatcher::refresh);
connect(renderer, &VncRenderer::framebufferObjectChanged, &(m_dispatcher->uploader()), &Uploader::changeFramebufferObject);
return renderer;
}
......
......@@ -6,6 +6,7 @@
#include <QQuickFramebufferObject>
#include <QThread>
#include <QOffscreenSurface>
#include <QMouseEvent>
#include "dispatcher.h"
#include "vncrenderer.h"
......@@ -41,6 +42,7 @@ public slots:
void setHost(QString host);
void setPort(int port);
void setMouse(int x, int y, bool left, bool middle, bool right);
void dispatch_error();
private:
......
......@@ -14,9 +14,6 @@ Uploader::Uploader()
m_copy_data.reserve(5);
m_copy_source->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)
......@@ -25,33 +22,57 @@ void Uploader::create_context(QOpenGLContext *context)
m_uploader_context->setShareContext(context);
m_uploader_context->create();
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()
{
// 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++) {
m_copy_source->at(i).texture->destroy();
delete m_copy_source->at(i).texture;
}
m_copy_source->clear();
m_copy_data.clear();
m_copy_count = 0;
m_fill_data.clear();
m_fill_count = 0;
for(unsigned int i = 0; i < m_draw_count; i++) {
m_draw_textures->at(i)->destroy();
delete m_draw_textures->at(i);
}
m_draw_textures->clear();
m_draw_data.clear();
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)
{
if(m_framebufferObject != NULL && !m_framebufferObject->isBound())
m_framebufferObject->bind();
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
// 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
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
m_draw_data.append((float) x);
......@@ -152,23 +173,26 @@ void Uploader::gotBitmap(const QImage &image, const int x, const int y, const in
void Uploader::finishedUpdate()
{
if(m_copy_count > 0) {
m_copy_buffer->bind();
m_copy_buffer->allocate(m_copy_data.constData(), m_copy_data.size() * sizeof(float));
m_copy_buffer->release();
if(m_fill_count > 0) {
m_fill_buffer.bind();
m_fill_buffer.allocate(m_fill_data.constData(), m_fill_data.size() * sizeof(float));
m_fill_buffer.release();
}
if(m_fill_count > 0) {
m_fill_buffer->bind();
m_fill_buffer->allocate(m_fill_data.constData(), m_fill_data.size() * sizeof(float));
m_fill_buffer->release();
if(m_copy_count > 0) {
m_copy_buffer.bind();
m_copy_buffer.allocate(m_copy_data.constData(), m_copy_data.size() * sizeof(float));
m_copy_buffer.release();
}
if(m_draw_count > 0) {
m_draw_buffer->bind();
m_draw_buffer->allocate(m_draw_data.data(), m_draw_data.size() * sizeof(float));
m_draw_buffer->release();
m_draw_buffer.bind();
m_draw_buffer.allocate(m_draw_data.data(), m_draw_data.size() * sizeof(float));
m_draw_buffer.release();
}
QOpenGLContext::currentContext()->functions()->glFlush();
if(m_framebufferObject != NULL && m_framebufferObject->isBound())
m_framebufferObject->release();
}
void Uploader::setFramebufferHeight(int framebufferHeight)
......@@ -191,22 +215,22 @@ unsigned int Uploader::draw_count() const
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;
}
......@@ -216,7 +240,7 @@ QSharedPointer<QVector<QOpenGLTexture *>> Uploader::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
#define UPLOADER_H
#include <QObject>
#include <QQuickWindow>
#include <QDebug>
#include <QVector>
......@@ -9,6 +10,7 @@
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QOpenGLTexture>
#include <QOpenGLFramebufferObject>
#include <QThreadPool>
#include <QtAlgorithms>
#include <QSharedPointer>
......@@ -21,8 +23,9 @@ typedef struct {
QOpenGLTexture *texture;
} copy;
class Uploader
class Uploader : public QObject
{
Q_OBJECT
public:
Uploader();
void create_context(QOpenGLContext *context);
......@@ -38,34 +41,37 @@ public:
unsigned int copy_count() const;
unsigned int draw_count() const;
QOpenGLBuffer fill_buffer();
QSharedPointer<QVector<copy>> copy_source();
QSharedPointer<QOpenGLBuffer> copy_buffer();
QSharedPointer<QOpenGLBuffer> fill_buffer();
QSharedPointer<QOpenGLBuffer> draw_buffer();
QOpenGLBuffer copy_buffer();
QOpenGLBuffer draw_buffer();
QSharedPointer<QVector<QOpenGLTexture *>> draw_textures();
QOpenGLContext *uploader_context() const;
private:
int m_framebufferHeight;
QOffscreenSurface m_surface;
QOpenGLContext *m_uploader_context;
unsigned int m_copy_count;
QVector<float> m_copy_data;
QSharedPointer<QVector<copy>> m_copy_source;
QSharedPointer<QOpenGLBuffer> m_copy_buffer;
QOpenGLFramebufferObject *m_framebufferObject;
unsigned int m_fill_count;
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;
QVector<float> m_draw_data;
QSharedPointer<QOpenGLBuffer> m_draw_buffer;
QOpenGLBuffer m_draw_buffer;
QSharedPointer<QVector<QOpenGLTexture*>> m_draw_textures;
uchar m_decoders_running;
public slots:
void changeFramebufferObject(QOpenGLFramebufferObject *framebufferObject);
};
#endif // UPLOADER_H
#include "vncrenderer.h"
VncRenderer::VncRenderer(QQuickWindow *window,
QSharedPointer<QOpenGLBuffer> fill_buffer,
QOpenGLBuffer fill_buffer,
QSharedPointer<QVector<copy>> copy_source,
QSharedPointer<QOpenGLBuffer> copy_buffer,
QSharedPointer<QOpenGLBuffer> draw_buffer,
QOpenGLBuffer copy_buffer,
QOpenGLBuffer draw_buffer,
QSharedPointer<QVector<QOpenGLTexture*>> draw_textures,
QObject *parent) :
QObject(parent), m_window(window), 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)
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_draw_buffer->create();
/*QOpenGLShader fill_vshader(QOpenGLShader::Vertex, &m_fill_program);
fill_vshader.compileSourceCode("uniform highp mat4 ortho;\n"
"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.addShaderFromSourceFile(QOpenGLShader::Vertex, "fill_shader.vsh");
m_fill_program.addShaderFromSourceFile(QOpenGLShader::Fragment, "fill_shader.fsh");
m_fill_program.bind();
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::Fragment, "draw_shader.fsh");
......@@ -42,34 +24,36 @@ VncRenderer::VncRenderer(QQuickWindow *window,
m_draw_program.enableAttributeArray("position");
m_draw_program.enableAttributeArray("texcoord");
m_draw_program.release();
m_functions = QOpenGLContext::currentContext()->functions();
}
void VncRenderer::render()
{
QOpenGLFunctions *fun = m_window->openglContext()->functions();
if(m_clear) {
fun->glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
fun->glClear(GL_COLOR_BUFFER_BIT);
m_functions->glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
m_functions->glClear(GL_COLOR_BUFFER_BIT);
m_clear = false;
}
/*if(m_fill_count > 0) {
if(m_fill_count > 0) {
m_fill_program.bind();
m_fill_program.enableAttributeArray("position");
m_fill_program.enableAttributeArray("color");
m_fill_buffer.bind();
m_fill_program.setAttributeBuffer("position", GL_FLOAT, 0, 2, 3 * sizeof(float));
m_fill_program.setAttributeBuffer("color", GL_FLOAT, 2, 3, 2 * sizeof(float));
m_fill_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 5 * 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++)
fun->glDrawArrays(GL_TRIANGLES, i * 4, 4);
m_functions->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4);
m_fill_buffer.release();
m_fill_program.release();
}
*/
if(m_copy_count > 0 || m_draw_count > 0)
m_draw_program.bind();
m_draw_program.enableAttributeArray("position");
m_draw_program.enableAttributeArray("texcoord");
/*
if(m_copy_count > 0){
m_copy_buffer.bind();
m_draw_program.setAttributeBuffer("position", GL_FLOAT, 0 * sizeof(float), 2, 4 * sizeof(float));
......@@ -77,32 +61,32 @@ void VncRenderer::render()
for(unsigned int i = 0; i < m_copy_count; i++) {
m_copy_source->at(i).texture->bind();
fun->glCopyTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
m_copy_source->at(i).src_x,
m_copy_source->at(i).src_y,
m_copy_source->at(i).width,
m_copy_source->at(i).height,
0);
fun->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4);
/*m_functions->glCopyTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
m_copy_source->at(i).src_x,
m_copy_source->at(i).src_y,
m_copy_source->at(i).width,
m_copy_source->at(i).height,
0);*/
m_functions->glDrawArrays(GL_TRIANGLE_STRIP, i * 4, 4);
m_copy_source->at(i).texture->release();
}
m_copy_buffer.release();
}*/
}
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("texcoord", GL_FLOAT, 2 * sizeof(float), 2, 4 * sizeof(float));
for(unsigned int i = 0; i < m_draw_count; i++) {
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_buffer->release();
m_draw_buffer.release();
}
if(m_copy_count > 0 || m_draw_count > 0)
......@@ -117,13 +101,15 @@ QOpenGLFramebufferObject *VncRenderer::createFramebufferObject(const QSize &size
{
QMatrix4x4 ortho;
ortho.ortho(QRect(QPoint(0, size.height()), QSize(size.width(), -1 * size.height())));
//m_fill_program.bind();
//m_fill_program.setUniformValue("ortho", ortho);
m_fill_program.bind();
m_fill_program.setUniformValue("ortho", ortho);
m_draw_program.bind();
m_draw_program.setUniformValue("ortho", ortho);
m_draw_program.release();
return new QOpenGLFramebufferObject(size);
QOpenGLFramebufferObject *framebufferObject = new QOpenGLFramebufferObject(size);
emit framebufferObjectChanged(framebufferObject);
return framebufferObject;
}
void VncRenderer::synchronize(QQuickFramebufferObject *object)
......@@ -133,4 +119,8 @@ void VncRenderer::synchronize(QQuickFramebufferObject *object)
m_fill_count = dispatcher->fill_count();
m_copy_count = dispatcher->copy_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
{
Q_OBJECT
public:
VncRenderer(QQuickWindow* window,
QSharedPointer<QOpenGLBuffer> fill_buffer,
VncRenderer(QQuickWindow *window,
QOpenGLBuffer fill_buffer,
QSharedPointer<QVector<copy>> copy_source,
QSharedPointer<QOpenGLBuffer> copy_buffer,
QSharedPointer<QOpenGLBuffer> draw_buffer,
QOpenGLBuffer copy_buffer,
QOpenGLBuffer draw_buffer,
QSharedPointer<QVector<QOpenGLTexture*>> draw_textures,
QObject *parent = 0);
protected:
......@@ -31,24 +31,23 @@ protected:
void synchronize(QQuickFramebufferObject *) override;
private:
QQuickWindow *m_window;
QOpenGLFunctions *m_functions;
bool m_clear;
unsigned int m_fill_count;
QOpenGLShaderProgram m_fill_program;
QSharedPointer<QOpenGLBuffer> m_fill_buffer;
QOpenGLBuffer m_fill_buffer;
unsigned int m_copy_count;
QSharedPointer<QVector<copy>> m_copy_source;
QSharedPointer<QOpenGLBuffer> m_copy_buffer;
QOpenGLBuffer m_copy_buffer;
unsigned int m_draw_count;
QOpenGLShaderProgram m_draw_program;
QSharedPointer<QOpenGLBuffer> m_draw_buffer;
QOpenGLBuffer m_draw_buffer;
QSharedPointer<QVector<QOpenGLTexture*>> m_draw_textures;
QMatrix4x4 m_ortho;
bool m_clear;
signals:
void framebufferObjectChanged(QOpenGLFramebufferObject *framebufferObject);
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