Example and fix for non-main render target with SyphonServer
This commit is contained in:
committed by
edwin
parent
4a1a4103c3
commit
6654a1737c
@@ -1,5 +1,4 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":orx-camera")
|
|
||||||
compile "org.openrndr:openrndr-core:$openrndrVersion"
|
compile "org.openrndr:openrndr-core:$openrndrVersion"
|
||||||
compile "org.openrndr:openrndr-gl3:$openrndrVersion"
|
compile "org.openrndr:openrndr-gl3:$openrndrVersion"
|
||||||
compile "org.lwjgl:lwjgl-opengl:3.2.3"
|
compile "org.lwjgl:lwjgl-opengl:3.2.3"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import jsyphon.JSyphonClient
|
import jsyphon.JSyphonClient
|
||||||
import jsyphon.JSyphonServer
|
import org.lwjgl.opengl.GL33C.GL_TEXTURE_RECTANGLE
|
||||||
import org.lwjgl.opengl.GL33C
|
|
||||||
import org.openrndr.Extension
|
import org.openrndr.Extension
|
||||||
import org.openrndr.Program
|
import org.openrndr.Program
|
||||||
import org.openrndr.draw.*
|
import org.openrndr.draw.*
|
||||||
@@ -14,19 +13,25 @@ class SyphonClient: Extension {
|
|||||||
var buffer: ColorBuffer = colorBuffer(10, 10)
|
var buffer: ColorBuffer = colorBuffer(10, 10)
|
||||||
|
|
||||||
override fun setup(program: Program) {
|
override fun setup(program: Program) {
|
||||||
var buffer = colorBuffer(program.width, program.height)
|
buffer = colorBuffer(program.width, program.height)
|
||||||
client.init()
|
client.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforeDraw(drawer: Drawer, program: Program) {
|
override fun beforeDraw(drawer: Drawer, program: Program) {
|
||||||
if (client.hasNewFrame()) {
|
if (client.hasNewFrame()) {
|
||||||
val img = client.newFrameImageForContext()
|
val img = client.newFrameImageForContext()
|
||||||
|
val name = img.textureName()
|
||||||
val w = img.textureWidth()
|
val w = img.textureWidth()
|
||||||
val h = img.textureHeight()
|
val h = img.textureHeight()
|
||||||
|
|
||||||
val rectBuffer = ColorBufferGL3(GL33C.GL_TEXTURE_RECTANGLE, img.textureName(), w, h,
|
/**
|
||||||
1.0, ColorFormat.RGBa, ColorType.UINT8, 0, BufferMultisample.Disabled, Session.root)
|
* GL_TEXTURE_RECTANGLE is necessary
|
||||||
|
*/
|
||||||
|
val rectBuffer = ColorBufferGL3(GL_TEXTURE_RECTANGLE, name, w, h, 1.0, ColorFormat.RGBa, ColorType.UINT8, 0, BufferMultisample.Disabled, Session.root)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only create a new buffer if it's size changed
|
||||||
|
*/
|
||||||
if (buffer.height != h || buffer.width != w) {
|
if (buffer.height != h || buffer.width != w) {
|
||||||
buffer = colorBuffer(w, h)
|
buffer = colorBuffer(w, h)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,31 +8,40 @@ import org.openrndr.draw.renderTarget
|
|||||||
import org.openrndr.internal.gl3.ColorBufferGL3
|
import org.openrndr.internal.gl3.ColorBufferGL3
|
||||||
|
|
||||||
|
|
||||||
class SyphonServer(private val name: String = "OPENRNDR", var target: RenderTarget? = null): Extension {
|
class SyphonServer(private val name: String = "OPENRNDR", var providedTarget: RenderTarget? = null): Extension {
|
||||||
override var enabled = true
|
override var enabled = true
|
||||||
private val server = JSyphonServer()
|
private val server = JSyphonServer()
|
||||||
|
private var targetToSend: RenderTarget? = null
|
||||||
|
|
||||||
override fun setup(program: Program) {
|
override fun setup(program: Program) {
|
||||||
server.initWithName(name)
|
server.initWithName(name)
|
||||||
|
|
||||||
if (target == null) {
|
// Create a new target that binds to the main one if no target is provided
|
||||||
target = renderTarget(program.width, program.height) {
|
if (providedTarget == null) {
|
||||||
|
targetToSend = renderTarget(program.width, program.height) {
|
||||||
colorBuffer()
|
colorBuffer()
|
||||||
depthBuffer()
|
depthBuffer()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
targetToSend = providedTarget
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun beforeDraw(drawer: Drawer, program: Program) {
|
override fun beforeDraw(drawer: Drawer, program: Program) {
|
||||||
target?.bind()
|
if (providedTarget == null) {
|
||||||
|
targetToSend?.bind()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun afterDraw(drawer: Drawer, program: Program) {
|
override fun afterDraw(drawer: Drawer, program: Program) {
|
||||||
target?.unbind()
|
if (providedTarget == null) {
|
||||||
drawer.image(target?.colorBuffer(0)!!)
|
targetToSend?.unbind()
|
||||||
val glBuffer = target?.colorBuffer(0) as ColorBufferGL3
|
// Actually draw it, necessary because of bind().
|
||||||
|
// Only draw if it's the main target.
|
||||||
|
drawer.image(targetToSend?.colorBuffer(0)!!)
|
||||||
|
}
|
||||||
|
|
||||||
println(glBuffer.target)
|
val glBuffer = targetToSend?.colorBuffer(0) as ColorBufferGL3
|
||||||
|
|
||||||
// Send to Syphon
|
// Send to Syphon
|
||||||
server.publishFrameTexture(
|
server.publishFrameTexture(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package jsyphon
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class JSyphonClient // public API
|
class JSyphonClient
|
||||||
{
|
{
|
||||||
private var ptr: Long = 0
|
private var ptr: Long = 0
|
||||||
|
|
||||||
@@ -52,11 +52,5 @@ class JSyphonClient // public API
|
|||||||
external fun newFrameDataForContext(ptr: Long = this.ptr): HashMap<String, Any>
|
external fun newFrameDataForContext(ptr: Long = this.ptr): HashMap<String, Any>
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
external fun stop(ptr: Long = this.ptr) // public JSyphonImage newFrameImageForContext() {
|
external fun stop(ptr: Long = this.ptr)
|
||||||
// HashMap<String, Object> dict = newFrameDataForContext();
|
|
||||||
// Long name = (Long)dict.get("name");
|
|
||||||
// Double width = (Double)dict.get("width");
|
|
||||||
// Double height = (Double)dict.get("height");
|
|
||||||
// return new JSyphonImage(name.intValue(), width.intValue(), height.intValue());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.isolatedWithTarget
|
||||||
|
import org.openrndr.draw.renderTarget
|
||||||
|
import kotlin.math.*
|
||||||
|
|
||||||
|
|
||||||
|
fun main() = application {
|
||||||
|
configure {
|
||||||
|
width = 1000
|
||||||
|
height = 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
program {
|
||||||
|
val rt = renderTarget(100, 100) {
|
||||||
|
colorBuffer()
|
||||||
|
}
|
||||||
|
|
||||||
|
extend(SyphonServer("Test", rt))
|
||||||
|
|
||||||
|
extend {
|
||||||
|
/**
|
||||||
|
* This is what will be sent to Syphon, and drawn in a small corner of the screen
|
||||||
|
*/
|
||||||
|
drawer.isolatedWithTarget(rt) {
|
||||||
|
drawer.background(ColorRGBa(sin(seconds), cos(seconds / 2.0), 0.5, 1.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
drawer.background(ColorRGBa.GRAY)
|
||||||
|
drawer.circle(width/2.0, height/2.0, sin(seconds) * width / 2.0)
|
||||||
|
drawer.image(rt.colorBuffer(0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user