Skip to content

Instantly share code, notes, and snippets.

@Skrylar
Created May 10, 2020 05:18
Show Gist options
  • Save Skrylar/8c42061559e03894fb009210d0d25857 to your computer and use it in GitHub Desktop.
Save Skrylar/8c42061559e03894fb009210d0d25857 to your computer and use it in GitHub Desktop.
Using a special unlock template to ensure sync flags are up to date
# TODO protect fields with inline procs that should get optimized out in release builds, but in debug builds can do asserts to make sure you unlocked it first
import opengl
import macros
import skyhash/xxhash
import sklog
type
TextureParameterBrush* = object
xhash*: uint64
min_filter*, max_filter*: Glint
wrap_s*, wrap_t*: Glint
proc `=changed`*(self: var TextureParameterBrush) =
## Updates the xhash of the parameter brush.
var state: XXH64State
template touch(x: untyped): untyped =
discard state.update(cast[pointer](unsafeaddr self.x), self.x.sizeof)
discard state.init 0
touch(max_filter)
touch(max_filter)
touch(wrap_s)
touch(wrap_t)
self.xhash = state.final
template unlock*(tex: var TextureParameterBrush; mutator: untyped): untyped =
block:
defer: `=changed`(tex)
mutator
var x: TextureParameterBrush
echo x.xhash
unlock x:
x.min_filter = GlNearest
x.max_filter = GlNearest
echo x.xhash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment