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

import ru.dbotthepony.kstarbound.client.StarboundClient
import ru.dbotthepony.kstarbound.client.gl.checkForGLError
import java.util.function.IntConsumer
import kotlin.reflect.KProperty

class GLStateFuncTracker(private val glFunc: IntConsumer, private var 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

		glFunc.accept(value)
		checkForGLError()
		this.value = value
	}
}