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

#pragma once

#include <ox/std/vec.hpp>

#include <nostalgia/gfx/color.hpp>

#include <glutils/glutils.hpp>

namespace nostalgia::gfx {

class TileSheetPixels {

	private:
		static constexpr auto VertexVboRows = 4;
		static constexpr auto VertexEboLength = 6;

		static const glutils::ProgramSource s_programSrc;
		float m_pixelSizeMod = 1;
		glutils::GLProgram m_shader;
		glutils::BufferSet m_bufferSet;
		class TileSheetEditorModel const &m_model;

	public:
		explicit TileSheetPixels(class TileSheetEditorModel &model) noexcept;

		void setPixelSizeMod(float sm) noexcept;

		ox::Error buildShader() noexcept;

		void draw(bool update, ox::Vec2 const &scroll) noexcept;

		void initBufferSet(ox::Vec2 const &paneSize) noexcept;

		void update(ox::Vec2 const &paneSize) noexcept;

		[[nodiscard]]
		ox::Vec2 pixelSize(ox::Vec2 const &paneSize) const noexcept;

	private:
		void setPixelBufferObject(
				ox::Vec2 const &paneSize,
				unsigned vertexRow,
				float x,
				float y,
				Color16 color,
				ox::Span<float> vbo,
				ox::Span<GLuint> ebo) const noexcept;

		void setBufferObjects(ox::Vec2 const &paneSize) noexcept;

};

}
