/*******************************************************************************
 *
 * Copyright (c) 2019 Gnarly Narwhal
 *
 * -----------------------------------------------------------------------------
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files(the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *******************************************************************************/

#include "../geno/GenoMacros.h"
#include "../geno/engine/GenoMonitor.h"

#include "Goal.h"

GenoTexture2D * Goal::texture = 0;
GenoShader2t  * Goal::shader  = 0;

Goal::Goal(GenoCamera2D * camera, const GenoVector2f & position) :
	Collidable(camera, position, { 1.0f, 2.0f }, { 0.0f, 0.0f }) {
	if (shader == 0) {
		shader = new GenoShader2t();

		uint32 textureParams[] = {
			GL_TEXTURE_MIN_FILTER, GL_LINEAR,
			GL_TEXTURE_MAG_FILTER, GL_LINEAR,
			GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE,
			GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE
		};
		
		const char * path = 0;
		float width = GenoMonitors::getPrimaryMonitor()->getDefaultVideoMode()->getWidth();
		if (width >= (2560 + 3840) * 0.5f)
			path = "res/img/Door4k.png";
		else if (width >= (1080 + 2560) * 0.5f)
			path = "res/img/Door1440p.png";
		else
			path = "res/img/Door1080p.png";

		GenoTexture2DCreateInfo textureInfo = {};
		textureInfo.type        = GENO_TEXTURE2D_TYPE_PNG;
		textureInfo.numParams   = GENO_ARRAY_SIZE(textureParams) / 2;
		textureInfo.params      = textureParams;
		textureInfo.texture     = path;

		texture = GenoTexture2D::create(textureInfo);
	}
}

void Goal::render() {
	texture->bind();
	shader->enable();
	shader->setMvp(translate2D(camera->getVPMatrix(), position).scale2D(dimensions));
	vao->render();
}

Goal::~Goal() {}