CallbackVideoTexture

abstract class CallbackVideoTexture(width: Int, height: Int, uploadFormat: Int, usePbo: Boolean = false) : Texture

Shared base for JVM-side video textures whose source pushes decoded frames from a worker thread (libVLC, FFmpeg, JavaCV, JavaFX MediaView-snapshot, …):

  • Subclasses call submitFrame (ByteArray or ByteBuffer) on the decoder thread; the base atomically publishes a fresh FrameBuf to the GL thread — lock-free.

  • On every bindTexture (GL thread), if a new frame is pending, the base atomically consumes it via getAndSet(null) and uploads via glTexSubImage2D (or glTexImage2D on first frame / resolution change). With nothing pending the upload is skipped — the driver keeps the previous frame's storage live.

Optimizations vs. a naive blit:

  • GL_TEXTURE_SWIZZLE_A = GL_ONE — sampler returns alpha=1.0 regardless of the texture bytes; eliminates a per-frame CPU pass to force every 4th byte to 0xFF.

  • glTexSubImage2D for steady-state — re-uploads pixels into existing GPU storage instead of re-allocating with glTexImage2D every frame.

  • Optional PBO path (usePbo) — uploads route through GL_PIXEL_UNPACK_BUFFER via glMapBufferRange(... INVALIDATE_BUFFER | UNSYNCHRONIZED) + memcpy + glUnmapBuffer. Driver hands back fresh staging memory directly while the previous transfer is still in flight; fewer driver round-trips than the bufferData(null) + bufferData(data) orphan idiom.

  • Lock-free frame publish — no synchronized between decoder and GL threads. Two AtomicReference<FrameBuf> slots (latest + recycled) serve as the producer / consumer queue; at steady state at most two ByteArrays exist in flight.

Internal format is GL_RGBA (which JoglKgl maps to renderable GL_RGBA8); upload pixel-format (uploadFormat) is whatever the decoder produces — GL_BGRA for libVLC RV32, FFmpeg/JavaCV after sws_scale, and JavaFX PixelFormat.byteBgra.

Inheritors

Constructors

Link copied to clipboard
constructor(width: Int, height: Int, uploadFormat: Int, usePbo: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard
val coordTransform: Matrix3
Link copied to clipboard

Caller opt-out for mipmap generation.

Link copied to clipboard
val height: Int
Link copied to clipboard
val target: Int
Link copied to clipboard
val width: Int

Functions

Link copied to clipboard
open override fun bindTexture(dc: DrawContext): Boolean
Link copied to clipboard
fun getTexParameter(name: Int): Int
Link copied to clipboard
fun getTextureName(dc: DrawContext): KglTexture
Link copied to clipboard
open override fun release(dc: DrawContext)

Frees any resources associated with this instance. After this method returns the rendering resource is invalid, and any associated GL object is deleted.

Link copied to clipboard
fun setTexParameter(name: Int, param: Int)