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

import org.lwjgl.opengl.GL11.glDisable
import org.lwjgl.opengl.GL11.glEnable
import ru.dbotthepony.kstarbound.client.StarboundClient
import ru.dbotthepony.kstarbound.client.gl.checkForGLError
import kotlin.reflect.KProperty

class GLStateSwitchTracker(private val enum: Int, private var value: Boolean = false) {
	operator fun getValue(glStateTracker: StarboundClient, property: KProperty<*>): Boolean {
		return value
	}

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

		if (value == this.value)
			return

		if (value) {
			glEnable(enum)
		} else {
			glDisable(enum)
		}

		checkForGLError()
		this.value = value
	}
}
