#include "runicpch.h"
#include "OpenGLGPUQuery.h"
#include "glad/glad.h"
namespace Runic {



	OpenGLTimeGPUQuery::OpenGLTimeGPUQuery(const std::string& name) : m_name(name)
	{
		glGenQueries(1, &m_qry_id);
	}
	OpenGLTimeGPUQuery::~OpenGLTimeGPUQuery()
	{
		glDeleteQueries(1, &m_qry_id);
	}
	void OpenGLTimeGPUQuery::Begin()
	{
		glBeginQuery(GL_TIME_ELAPSED, m_qry_id);
	}
	void OpenGLTimeGPUQuery::End()
	{
		glEndQuery(GL_TIME_ELAPSED);
	}
	bool OpenGLTimeGPUQuery::Available()
	{
		int32_t res = false;
		glGetQueryObjectiv(m_qry_id, GL_QUERY_RESULT_AVAILABLE, &res);
		return res;
	}
	uint64_t OpenGLTimeGPUQuery::Result()
	{
		glGetQueryObjectui64v(m_qry_id, GL_QUERY_RESULT, &m_gpu_time);
		return m_gpu_time;
	}
}