Skip to content

Commit

Permalink
Some improvements, new Linux natives
Browse files Browse the repository at this point in the history
  • Loading branch information
Штенгауэр Никита Дмитриевич committed Dec 3, 2023
1 parent 6f42684 commit dc0ca3a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ open class AsyncNVDXInteropCanvasImpl(
}

glViewport(0, 0, drawSize.width, drawSize.height)
canvas.fireRenderEvent(if (msaaFBO != null) msaaFBO!!.id else fbo.id)
if (msaaFBO != null)
msaaFBO!!.blitTo(fbo)
canvas.fireRenderEvent(msaaFBO?.id ?: fbo.id)
msaaFBO?.blitTo(fbo)
}

private fun updateFramebufferSize(width: Int, height: Int) {
if (::fbo.isInitialized) {
fbo.delete()
if(msaaFBO != null) msaaFBO!!.delete()
msaaFBO?.delete()
}

// Create GL texture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ open class AsyncSharedCanvasImpl(
private lateinit var fxContext: GLContext

private lateinit var fbo: Framebuffer
private lateinit var msaaFBO: MultiSampledFramebuffer
private var msaaFBO: MultiSampledFramebuffer? = null
private lateinit var transferFBO: Framebuffer
private lateinit var resultFBO: Framebuffer

Expand Down Expand Up @@ -79,22 +79,27 @@ open class AsyncSharedCanvasImpl(
if(::resultFBO.isInitialized) resultFBO.delete()
if(::transferFBO.isInitialized) transferFBO.delete()
if(::fbo.isInitialized) fbo.delete()
if(::msaaFBO.isInitialized) msaaFBO.delete()
msaaFBO?.delete()

GLContext.delete(context)
GLContext.delete(fxWrapperContext)
fxContext.makeCurrent()
}
}
}

private fun paint(){
drawSize.executeOnDifferenceWith(scaledSize, ::updateRenderFramebufferSize, canvas::fireReshapeEvent)
if(drawSize != scaledSize ||
msaa != (msaaFBO?.requestedSamples ?: 0)
){
scaledSize.copyTo(drawSize)
updateRenderFramebufferSize(drawSize.width, drawSize.height)
canvas.fireReshapeEvent(drawSize.width, drawSize.height)
}

glViewport(0, 0, drawSize.width, drawSize.height)
canvas.fireRenderEvent(if(msaa != 0) msaaFBO.id else fbo.id)
if(msaa != 0)
msaaFBO.blitTo(fbo)
glFinish()
canvas.fireRenderEvent(msaaFBO?.id ?: fbo.id)
msaaFBO?.blitTo(fbo)
}

override fun renderContent(g: Graphics) {
Expand Down Expand Up @@ -142,18 +147,18 @@ open class AsyncSharedCanvasImpl(
private fun updateRenderFramebufferSize(width: Int, height: Int) {
if(::fbo.isInitialized){
fbo.delete()
if(msaa != 0) msaaFBO.delete()
msaaFBO?.delete()
}

// Create framebuffer
fbo = Framebuffer(width, height)
fbo.bindFramebuffer()

// Create multi-sampled framebuffer
if(msaa != 0){
if(msaa > 0){
msaaFBO = MultiSampledFramebuffer(msaa, width, height)
msaaFBO.bindFramebuffer()
}
msaaFBO!!.bindFramebuffer()
} else msaaFBO = null
}

override fun repaint() {
Expand Down
Binary file not shown.
Binary file not shown.
11 changes: 10 additions & 1 deletion modules/lwjgl/src/examples/kotlin/LWJGL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import javafx.scene.layout.*
import javafx.scene.layout.Region.USE_PREF_SIZE
import javafx.scene.paint.Paint
import javafx.stage.Stage
import org.lwjgl.opengl.GL11.glGetInteger
import org.lwjgl.opengl.GL30.GL_MAJOR_VERSION
import org.lwjgl.opengl.GL30.GL_MINOR_VERSION
import scene.ExampleScene


Expand All @@ -32,6 +35,8 @@ class ExampleApp: Application(){

private lateinit var stage: Stage
private lateinit var canvas: GLCanvas
private var majorVersion = -1
private var minorVersion = -1
private var iteration = 0

override fun start(stage: Stage) {
Expand Down Expand Up @@ -118,7 +123,7 @@ class ExampleApp: Application(){
"GLInteropType" to { canvas.interopType },
"Impl" to { RegionHelper.getPeer<NGGLCanvas>(canvas)::class.java.simpleName },
separator,
"GLProfile" to { canvas.profile },
"GLProfile" to { "${canvas.profile} ${majorVersion}.${minorVersion}" },
"Async" to { canvas.async },
"Flip-Y" to { canvas.flipY },
"MSAA" to { canvas.msaa },
Expand All @@ -144,6 +149,10 @@ class ExampleApp: Application(){
}
}
canvas.addOnRenderEvent { e ->
if(majorVersion == -1)
majorVersion = glGetInteger(GL_MAJOR_VERSION)
if(minorVersion == -1)
minorVersion = glGetInteger(GL_MINOR_VERSION)
Platform.runLater {
labels.forEach {
it.key.text = it.value().toString()
Expand Down

0 comments on commit dc0ca3a

Please sign in to comment.