Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ dependencies {

api("sc.fiji:bigdataviewer-core:10.4.14")
api("sc.fiji:bigdataviewer-vistools:1.0.0-beta-28")
api("sc.fiji:bigvolumeviewer:0.3.3") {
api("sc.fiji:bigvolumeviewer:0.4.1") {
exclude("org.jogamp.gluegen", "gluegen-rt")
exclude("org.jogamp.jogl", "jogl-all")
}
Expand Down
92 changes: 70 additions & 22 deletions src/main/kotlin/graphics/scenery/volumes/SceneryContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ open class SceneryContext(val node: VolumeManager, val useCompute: Boolean = fal

/** Factory for the autogenerated shaders. */
val factory = VolumeShaderFactory(useCompute)
/** Reference to the currently bound texture cache. */
protected var currentlyBoundCache: Texture? = null
/** Reference to the currently bound R8 texture cache. */
protected var currentlyBoundR8Cache: Texture? = null
/** Reference to the currently bound R16 texture cache. */
protected var currentlyBoundR16Cache: Texture? = null
/** Hashmap for references to the currently bound LUTs/texture atlases. */
protected var currentlyBoundTextures = ConcurrentHashMap<String, Texture>()
/** Hashmap for storing associations between [Texture] objects, texture slots and uniform names. */
Expand Down Expand Up @@ -353,26 +355,70 @@ open class SceneryContext(val node: VolumeManager, val useCompute: Boolean = fal

val material = node.material()
if (texture is TextureCache) {
if(currentlyBoundCache != null && material.textures["volumeCache"] == currentlyBoundCache && dimensionsMatch(texture, material.textures["volumeCache"])) {
return 0
val cacheName = bindings[texture]?.uniformName
var db: (String) -> Unit = { _ -> }
if(texture.spec().format() == bvv.core.backend.Texture.InternalFormat.R8) {
db = { name: String ->

if (!(currentlyBoundR8Cache != null && material.textures[name] == currentlyBoundR8Cache && dimensionsMatch(
texture,
material.textures[name]
))
) {
// logger.warn("Binding and updating cache $texture")
val gt = UpdatableTexture(
Vector3i(texture.texWidth(), texture.texHeight(), texture.texDepth()),
channels,
type,
null,
repeat.all(),
BorderColor.TransparentBlack,
normalized,
false,
minFilter = Texture.FilteringMode.Linear,
maxFilter = Texture.FilteringMode.Linear
)

material.textures[name] = gt
currentlyBoundR8Cache = gt
}
}

}
else
{
db = { name: String ->
if (!(currentlyBoundR16Cache != null && material.textures[name] == currentlyBoundR16Cache && dimensionsMatch(
texture,
material.textures[name]
))
) {
// logger.warn("Binding and updating cache $texture")
val gt = UpdatableTexture(
Vector3i(texture.texWidth(), texture.texHeight(), texture.texDepth()),
channels,
type,
null,
repeat.all(),
BorderColor.TransparentBlack,
normalized,
false,
minFilter = Texture.FilteringMode.Linear,
maxFilter = Texture.FilteringMode.Linear
)

material.textures[name] = gt
currentlyBoundR16Cache = gt
}
}
}
if(cacheName == null) {
deferredBindings[texture] = db
return -1
} else {
db.invoke(cacheName)
}

// logger.warn("Binding and updating cache $texture")
val gt = UpdatableTexture(
Vector3i(texture.texWidth(), texture.texHeight(), texture.texDepth()),
channels,
type,
null,
repeat.all(),
BorderColor.TransparentBlack,
normalized,
false,
minFilter = Texture.FilteringMode.Linear,
maxFilter = Texture.FilteringMode.Linear)

material.textures["volumeCache"] = gt

currentlyBoundCache = gt
} else {
val textureName = bindings[texture]?.uniformName
logger.debug("lutName is $textureName for $texture")
Expand All @@ -385,7 +431,8 @@ open class SceneryContext(val node: VolumeManager, val useCompute: Boolean = fal
*/
if (!(material.textures[name] != null
&& currentlyBoundTextures[name] != null
&& material.textures[name] == currentlyBoundTextures[name])) {
&& material.textures[name] == currentlyBoundTextures[name]))
{
val contents = when(texture) {
is LookupTextureARGB -> null
is VolumeManager.SimpleTexture2D -> texture.data
Expand Down Expand Up @@ -459,7 +506,8 @@ open class SceneryContext(val node: VolumeManager, val useCompute: Boolean = fal
fun clearCacheBindings() {
val caches = bindings.filter { it is TextureCache }
caches.map { bindings.remove(it.key) }
currentlyBoundCache = null
currentlyBoundR8Cache = null
currentlyBoundR16Cache = null
}

fun clearBindings() {
Expand Down
Loading