/*
 * Copyright 2023 - 2025 Gary Talent (gary@drinkingtea.net). All rights reserved.
 */

#pragma once

#include <glutils/glutils.hpp>

#include <studio/context.hpp>
#include <nostalgia/gfx/gfx.hpp>

#include <jasper/world/worldobject.hpp>

namespace jasper::world {

namespace ngfx = nostalgia::gfx;

class MapTileHighlighter {
	private:
		static const glutils::ProgramSource s_programSrc;
		static constexpr int s_scale = 5;
		glutils::GLProgram m_shader;
		glutils::BufferSet m_bufferSet;
		int32_t m_subsheetTilesWidth{};
		int32_t m_subsheetTilesHeight{};

	public:
		MapTileHighlighter();

		ox::Error setup(ox::Size const &sz) noexcept;

		void draw() noexcept;

		ox::Error setTileHighlight(ox::Point const &addr, bool hl) noexcept;

		[[nodiscard]]
		static int scale() noexcept;

	private:
		static void setPixelBufferObject(
				uint_t vertexRow,
				float x, float y,
				bool selected,
				float *vbo,
				GLuint *ebo) noexcept;

		void initGlBuffers() noexcept;
};

}
