Skip to content

Commit

Permalink
Syphon In
Browse files Browse the repository at this point in the history
  • Loading branch information
gjacquemin committed Apr 12, 2016
1 parent f84becd commit 6d16655
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 41 deletions.
4 changes: 2 additions & 2 deletions abstractionsgl.cpp
Expand Up @@ -364,8 +364,8 @@ bool OpenGlTexture::pushTexture() {
verboseTexte = QString("[OPENGL] Création de la texture #%1 => %2 (%3)").arg(texture).arg(filename).arg(texte);
}
glBindTexture (GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//GL_NEAREST
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);//GL_NEAREST_MIPMAP_LINEAR
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Expand Down
2 changes: 1 addition & 1 deletion interfaces/interfacesyphon.h
Expand Up @@ -44,7 +44,7 @@ class InterfaceSyphon : public NetworkInterface {
public:
UiBool serverEnable, clientEnable;
bool serverInit, clientInit, clientTextureOk;
GLuint serverTexture;
GLuint serverTexture, clientTexture;
private:
void *serverSyphon, *clientSyphon;

Expand Down
11 changes: 7 additions & 4 deletions interfaces/interfacesyphon.mm
Expand Up @@ -34,14 +34,16 @@
ui(new Ui::InterfaceSyphon) {
ui->setupUi(this);

//Interfaces link
serverEnable.setAction(ui->serverEnable, "interfaceSyphonServerEnable");
clientEnable.setAction(ui->clientEnable, "interfaceSyphonClientEnable");

//Init code
serverInit = false;
serverTexture = 0;
serverSyphon = nil;
clientInit = false;
clientSyphon = 0;
clientTexture = 0;
clientSyphon = nil;
initSyphonServer();
}

Expand Down Expand Up @@ -79,6 +81,7 @@
if(servers) {
if([servers.servers count] > 0) {
clientSyphon = [[SyphonClient alloc] initWithServerDescription:[servers.servers objectAtIndex:0] options:nil newFrameHandler:^(SyphonClient *clientSyphon) {
clientInit = true;
clientTextureOk = true;
}];
}
Expand All @@ -97,13 +100,13 @@
clientTextureOk = false;
SyphonImage *frame = [(SyphonClient*)clientSyphon newFrameImageForContext:CGLGetCurrentContext()];
if(frame) {
GLuint texture = frame.textureName;
clientTexture = frame.textureName;
if(size) {
size->setWidth(frame.textureSize.width);
size->setHeight(frame.textureSize.height);
}
[frame release];
return texture;
return clientTexture;
}
return 0;
}
Expand Down
21 changes: 20 additions & 1 deletion interfaces/interfacesyphon.ui
Expand Up @@ -20,7 +20,16 @@
<property name="spacing">
<number>5</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
Expand All @@ -33,6 +42,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="clientEnable">
<property name="toolTip">
<string>Enables or disables score rendering output through Syphon</string>
</property>
<property name="text">
<string>ENABLE SYPHON IN</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
2 changes: 2 additions & 0 deletions misc/options.h
Expand Up @@ -61,12 +61,14 @@ class UiRenderTexture {
QFileInfo filename;
GLuint texture;
bool loaded;
bool isSyphon;
NxRect mapping;
QSizeF originalSize;
public:
explicit UiRenderTexture() { loaded = false; }
explicit UiRenderTexture(const QString & _name, const QFileInfo & _filename, const NxRect & _mapping) {
loaded = false;
isSyphon = false;
name = _name;
filename = _filename;
mapping = _mapping;
Expand Down
35 changes: 24 additions & 11 deletions objects/nxcursor.cpp
Expand Up @@ -324,21 +324,34 @@ void NxCursor::paint() {
glRotatef(cursorAngle.z(), 0, 0, 1);
glRotatef(cursorAngle.y(), 0, 1, 0);
glRotatef(cursorAngle.x(), 1, 0, 0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texture);

qreal widthRatio = width * texture->originalSize.width() / texture->originalSize.height();

glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex3f(widthRatio * texture->mapping.left(), width/2 * texture->mapping.bottom(), 0);
glTexCoord2d(1, 0); glVertex3f(0, width/2 * texture->mapping.bottom(), 0);
glTexCoord2d(1, 1); glVertex3f(0, width/2 * texture->mapping.top(), 0);
glTexCoord2d(0, 1); glVertex3f(widthRatio * texture->mapping.left(), width/2 * texture->mapping.top(), 0);
glEnd();
if(texture->isSyphon) {
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture->texture);
glBegin(GL_QUADS);
qreal widthRatio = width * texture->originalSize.width() / texture->originalSize.height();
glTexCoord2d(0, 0); glVertex3f(widthRatio * texture->mapping.left(), width/2 * texture->mapping.bottom(), 0);
glTexCoord2d(texture->originalSize.width(), 0); glVertex3f(0, width/2 * texture->mapping.bottom(), 0);
glTexCoord2d(texture->originalSize.width(), texture->originalSize.height()); glVertex3f(0, width/2 * texture->mapping.top(), 0);
glTexCoord2d(0, texture->originalSize.height()); glVertex3f(widthRatio * texture->mapping.left(), width/2 * texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
else {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texture);
qreal widthRatio = width * texture->originalSize.width() / texture->originalSize.height();
glBegin(GL_QUADS);
glTexCoord2d(0, 0); glVertex3f(widthRatio * texture->mapping.left(), width/2 * texture->mapping.bottom(), 0);
glTexCoord2d(1, 0); glVertex3f(0, width/2 * texture->mapping.bottom(), 0);
glTexCoord2d(1, 1); glVertex3f(0, width/2 * texture->mapping.top(), 0);
glTexCoord2d(0, 1); glVertex3f(widthRatio * texture->mapping.left(), width/2 * texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_2D);
}

glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
}
if(!textureOk) {
Expand Down
35 changes: 25 additions & 10 deletions objects/nxtrigger.cpp
Expand Up @@ -114,16 +114,31 @@ void NxTrigger::paint() {
UiRenderTexture *texture = Render::textures->value(textureName);
if((texture) && (texture->loaded) && (texture->mapping.width() != 0 ) && (texture->mapping.height() != 0)) {
textureOk = true;
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texture);
glBegin(GL_QUADS);
qreal widthRatio = cacheSize * texture->originalSize.width() / texture->originalSize.height();
glTexCoord2d(0, 0); glVertex3f(widthRatio * texture->mapping.left(), cacheSize * texture->mapping.bottom(), 0);
glTexCoord2d(1, 0); glVertex3f(widthRatio * texture->mapping.right(), cacheSize * texture->mapping.bottom(), 0);
glTexCoord2d(1, 1); glVertex3f(widthRatio * texture->mapping.right(), cacheSize * texture->mapping.top(), 0);
glTexCoord2d(0, 1); glVertex3f(widthRatio * texture->mapping.left(), cacheSize * texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_2D);

if(texture->isSyphon) {
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture->texture);
glBegin(GL_QUADS);
qreal widthRatio = cacheSize * texture->originalSize.width() / texture->originalSize.height();
glTexCoord2d(0, 0); glVertex3f(widthRatio * texture->mapping.left(), cacheSize * texture->mapping.bottom(), 0);
glTexCoord2d(texture->originalSize.width(), 0); glVertex3f(widthRatio * texture->mapping.right(), cacheSize * texture->mapping.bottom(), 0);
glTexCoord2d(texture->originalSize.width(), texture->originalSize.height()); glVertex3f(widthRatio * texture->mapping.right(), cacheSize * texture->mapping.top(), 0);
glTexCoord2d(0, texture->originalSize.height()); glVertex3f(widthRatio * texture->mapping.left(), cacheSize * texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
else {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texture);
glBegin(GL_QUADS);
qreal widthRatio = cacheSize * texture->originalSize.width() / texture->originalSize.height();
glTexCoord2d(0, 0); glVertex3f(widthRatio * texture->mapping.left(), cacheSize * texture->mapping.bottom(), 0);
glTexCoord2d(1, 0); glVertex3f(widthRatio * texture->mapping.right(), cacheSize * texture->mapping.bottom(), 0);
glTexCoord2d(1, 1); glVertex3f(widthRatio * texture->mapping.right(), cacheSize * texture->mapping.top(), 0);
glTexCoord2d(0, 1); glVertex3f(widthRatio * texture->mapping.left(), cacheSize * texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_2D);
}
}
}
if(!textureOk) {
Expand Down
51 changes: 39 additions & 12 deletions render/uirender.cpp
Expand Up @@ -99,8 +99,9 @@ bool UiRender::loadTexture(UiRenderTexture *texture, bool gl) {
glBindTexture(GL_TEXTURE_2D, texture->texture);
QImage tex = QGLWidget::convertToGLFormat(QImage(texture->filename.absoluteFilePath()));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width(), tex.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, tex.bits());
glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glDisable(GL_TEXTURE_2D);
texture->originalSize = tex.size();
texture->loaded = true;
Expand Down Expand Up @@ -576,6 +577,17 @@ void UiRender::paintGL() {
interfaceSyphon->publishTexture(GL_TEXTURE_2D, renderSize.width(), renderSize.height());
glDisable(GL_TEXTURE_2D);
}

//Import Syphon
if(!interfaceSyphon->clientInit) {
makeCurrent();
interfaceSyphon->createSyphonClient();
Render::textures->insert("syphon", new UiRenderTexture("syphon", QFileInfo(), NxRect(-4, 4, 8, -8)));
}
if(interfaceSyphon->clientEnable) {
Render::textures->value("syphon")->texture = interfaceSyphon->getTexture(&Render::textures->value("syphon")->originalSize);
Render::textures->value("syphon")->loaded = Render::textures->value("syphon")->isSyphon = true;
}
#endif

//Mode performance preview
Expand Down Expand Up @@ -607,17 +619,32 @@ void UiRender::paintBackground() {
if(Render::textures->contains("background")) {
UiRenderTexture *texture = Render::textures->value("background");
if((texture) && (texture->loaded) && (texture->mapping.width() != 0) && (texture->mapping.height() != 0)) {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texture);
glBegin(GL_QUADS);
qglColor(Render::colors->value("background_texture_tint"));
glLineWidth(1);
glTexCoord2d(0, 0); glVertex3f(texture->mapping.left() , texture->mapping.bottom(), 0);
glTexCoord2d(1, 0); glVertex3f(texture->mapping.right(), texture->mapping.bottom(), 0);
glTexCoord2d(1, 1); glVertex3f(texture->mapping.right(), texture->mapping.top(), 0);
glTexCoord2d(0, 1); glVertex3f(texture->mapping.left() , texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_2D);
if(texture->isSyphon) {
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture->texture);
glBegin(GL_QUADS);
qglColor(Render::colors->value("background_texture_tint"));
glLineWidth(1);
glTexCoord2d(0, 0); glVertex3f(texture->mapping.left() , texture->mapping.bottom(), 0);
glTexCoord2d(texture->originalSize.width(), 0); glVertex3f(texture->mapping.right(), texture->mapping.bottom(), 0);
glTexCoord2d(texture->originalSize.width(), texture->originalSize.height()); glVertex3f(texture->mapping.right(), texture->mapping.top(), 0);
glTexCoord2d(0, texture->originalSize.height()); glVertex3f(texture->mapping.left() , texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
else {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture->texture);
glBegin(GL_QUADS);
qglColor(Render::colors->value("background_texture_tint"));
glLineWidth(1);
glTexCoord2d(0, 0); glVertex3f(texture->mapping.left() , texture->mapping.bottom(), 0);
glTexCoord2d(1, 0); glVertex3f(texture->mapping.right(), texture->mapping.bottom(), 0);
glTexCoord2d(1, 1); glVertex3f(texture->mapping.right(), texture->mapping.top(), 0);
glTexCoord2d(0, 1); glVertex3f(texture->mapping.left() , texture->mapping.top(), 0);
glEnd();
glDisable(GL_TEXTURE_2D);
}
}
}
}
Expand Down

0 comments on commit 6d16655

Please sign in to comment.