package ru.dbotthepony.kstarbound.client.gl.properties

import ru.dbotthepony.kstarbound.client.StarboundClient
import ru.dbotthepony.kstarbound.client.gl.checkForGLError
import kotlin.reflect.KProperty

class GLStateIntTracker(private val fn: Function, private val enum: Int, private var value: Int) {
	fun interface Function {
		fun invoke(enum: Int, value: Int)
	}

	operator fun getValue(glStateTracker: StarboundClient, property: KProperty<*>): Int {
		return value
	}

	operator fun setValue(glStateTracker: StarboundClient, property: KProperty<*>, value: Int) {
		glStateTracker.ensureSameThread()

		if (value == this.value)
			return

		fn.invoke(enum, value)
		checkForGLError()
		this.value = value
	}
}