Source

GL Profile Suite / tests / util / globj.cpp



#include <algorithm>
#include <iterator>
#include "globj.h"


namespace util
{
	GLuint CreateBufferObject()
	{
		GLuint buffer;
		glGenBuffers(1, &buffer);
		return buffer;
	}

	std::vector<GLuint> CreateBufferObjects( int numBuffers )
	{
		std::vector<GLuint> buffers(numBuffers);
		glGenBuffers(numBuffers, &buffers[0]);
		return buffers;
	}

	void DestroyBufferObjects( const std::vector<GLuint> &buffers )
	{
		glDeleteBuffers(buffers.size(), &buffers[0]);
	}

	std::vector<GLuint> CreateVertexArrays( int numArrays )
	{
		std::vector<GLuint> arrays(numArrays);
		glGenVertexArrays(numArrays, &arrays[0]);
		return arrays;
	}

	void DestroyVertexArrays( const std::vector<GLuint> &arrays )
	{
		glDeleteVertexArrays(arrays.size(), &arrays[0]);
	}

	GLuint CreateQuery()
	{
		GLuint query;
		glGenQueries(1, &query);
		return query;
	}

	std::vector<GLuint> CreateQueries( int numQueries )
	{
		std::vector<GLuint> queries(numQueries);
		glGenQueries(numQueries, &queries[0]);
		return queries;
	}

	void DestroyQueries( const std::vector<GLuint> &queries )
	{
		glDeleteQueries(queries.size(), &queries[0]);
	}

	std::vector<GLuint> CreatePrograms( int numPrograms )
	{
		std::vector<GLuint> programs;
		programs.reserve(numPrograms);
		std::generate_n(std::back_inserter(programs), numPrograms, glCreateProgram);
		return programs;
	}

	void DestroyPrograms( const std::vector<GLuint> &programs )
	{
		std::for_each(programs.begin(), programs.end(), glDeleteProgram);
	}
}