
#include "OpenGLDrv.h"
#include <Graphics/GL/gl.h>

namespace sp {

std::string OpenGLDrv::getVendor() const
{
	char buf[512];

	std::string prof = "Compability";
	char *ver = (char*) glGetString(GL_VERSION);
	char *ven = (char*) glGetString(GL_VENDOR);
	char *ren = (char*) glGetString(GL_RENDERER);
	GLint flags;

	glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &flags);
	if (flags & GL_CONTEXT_CORE_PROFILE_BIT) {
		prof = "Core";
	}

	snprintf(buf, sizeof(buf), "OpenGL %s %s profile - %s %s", ver, prof.c_str(), ren, ven);

	return std::string(buf);
}

void OpenGLDrv::setViewport(int x, int y, int width, int height)
{
	glViewport(x, y, width, height);
}

void OpenGLDrv::setClearColor(float r, float g, float b, float a)
{
	glClearColor(r, g, b, 1.0f);
}

void OpenGLDrv::clearBuffer(GfxDriver::BufferFlags flags)
{
	int glFlags = 0;

	if (flags == GfxDriver::CLEAR_BUFFER_BIT) {
		glFlags |= GL_COLOR_BUFFER_BIT;
	}

	glClear(glFlags);
}

void OpenGLDrv::clearColorBuffer()
{
	glClear(GL_COLOR_BUFFER_BIT);
}

} // namespace sp
